diff options
Diffstat (limited to 'Authentication')
-rw-r--r-- | Authentication/Callback/index.php | 14 | ||||
-rw-r--r-- | Authentication/PublicCallback/index.php | 3 | ||||
-rw-r--r-- | Authentication/PublicStart/index.php | 3 | ||||
-rw-r--r-- | Authentication/Start/index.php | 5 |
4 files changed, 11 insertions, 14 deletions
diff --git a/Authentication/Callback/index.php b/Authentication/Callback/index.php index 4c591af..508326b 100644 --- a/Authentication/Callback/index.php +++ b/Authentication/Callback/index.php @@ -1,7 +1,6 @@ <?php -$channel = "private"; -$server = "privateauth.equestria.dev"; +$server = "auth.equestria.horse"; header("Content-Type: text/plain"); @@ -9,18 +8,18 @@ if (!isset($_GET['code'])) { die(); } -$appdata = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true)[$channel]; +$appdata = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true); $crl = curl_init('https://' . $server . '/hub/api/rest/oauth2/token'); curl_setopt($crl, CURLOPT_RETURNTRANSFER, true); curl_setopt($crl, CURLINFO_HEADER_OUT, true); curl_setopt($crl, CURLOPT_POST, true); curl_setopt($crl, CURLOPT_HTTPHEADER, [ - "Authorization: Basic " . base64_encode($appdata["id"] . ":" . $appdata["secret"]), + "Authorization: Basic " . base64_encode($appdata["oauth"]["id"] . ":" . $appdata["oauth"]["secret"]), "Content-Type: application/x-www-form-urlencoded", "Accept: application/json" ]); -curl_setopt($crl, CURLOPT_POSTFIELDS, "grant_type=authorization_code&redirect_uri=" . urlencode("http" . ($_SERVER['HTTPS'] ? "s" : "") . "://" . $_SERVER['HTTP_HOST'] . "/Authentication/Callback") . "&code=" . $_GET['code']); +curl_setopt($crl, CURLOPT_POSTFIELDS, "grant_type=authorization_code&redirect_uri=" . urlencode("https://ponies.equestria.horse/Authentication/Callback") . "&code=" . $_GET['code']); $result = curl_exec($crl); $result = json_decode($result, true); @@ -39,6 +38,11 @@ if (isset($result["access_token"])) { $result = curl_exec($crl); $result = json_decode($result, true); + if (!in_array($result["id"], $appdata["oauth"]["allowed"])) { + header("Location: /"); + die(); + } + if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens")) mkdir($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens"); $token = bin2hex(random_bytes(32)); diff --git a/Authentication/PublicCallback/index.php b/Authentication/PublicCallback/index.php deleted file mode 100644 index 7f6a11b..0000000 --- a/Authentication/PublicCallback/index.php +++ /dev/null @@ -1,3 +0,0 @@ -<?php - -return;
\ No newline at end of file diff --git a/Authentication/PublicStart/index.php b/Authentication/PublicStart/index.php deleted file mode 100644 index 7f6a11b..0000000 --- a/Authentication/PublicStart/index.php +++ /dev/null @@ -1,3 +0,0 @@ -<?php - -return;
\ No newline at end of file diff --git a/Authentication/Start/index.php b/Authentication/Start/index.php index 18bde88..99f393f 100644 --- a/Authentication/Start/index.php +++ b/Authentication/Start/index.php @@ -1,7 +1,6 @@ <?php -$channel = "private"; -$server = "privateauth.equestria.dev"; +$server = "auth.equestria.horse"; -header("Location: https://$server/hub/api/rest/oauth2/auth?client_id=" . json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true)[$channel]["id"] . "&response_type=code&redirect_uri=http" . ($_SERVER['HTTPS'] ? "s" : "") . "://" . $_SERVER['HTTP_HOST'] . "/Authentication/Callback&scope=Hub&request_credentials=default&access_type=offline"); +header("Location: https://$server/hub/api/rest/oauth2/auth?client_id=" . json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true)["oauth"]["id"] . "&response_type=code&redirect_uri=https://ponies.equestria.horse/Authentication/Callback&scope=Hub&request_credentials=default&access_type=offline"); die(); |