summaryrefslogtreecommitdiff
path: root/Authentication/Callback/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'Authentication/Callback/index.php')
-rw-r--r--Authentication/Callback/index.php14
1 files changed, 9 insertions, 5 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));