summaryrefslogtreecommitdiff
path: root/Authentication/Callback/index.php
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2023-01-29 15:19:02 +0100
committerMinteck <contact@minteck.org>2023-01-29 15:19:02 +0100
commitbdc6e413162587faea3e528fed4efa81e0f8a73f (patch)
tree36da38844f84b5cf84b0a6e3b942f0a04b09111a /Authentication/Callback/index.php
parentee4628eb4596c1c12a7efcbfc04abd2d48f05f0b (diff)
downloadpluralconnect-bdc6e413162587faea3e528fed4efa81e0f8a73f.tar.gz
pluralconnect-bdc6e413162587faea3e528fed4efa81e0f8a73f.tar.bz2
pluralconnect-bdc6e413162587faea3e528fed4efa81e0f8a73f.zip
Updated 3 files and deleted 2 files (automated)
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));