fix: fix auth

This commit is contained in:
TheClashFruit 2023-09-15 17:25:33 +02:00
parent c9eae5ea8c
commit 0689c5f844
Signed by: TheClashFruit
GPG key ID: CF4A319B9A73290C
2 changed files with 15 additions and 9 deletions

View file

@ -8,20 +8,26 @@
if(isset($_GET['code'])) { if(isset($_GET['code'])) {
$res = $discord->validateCode($_GET['code']); $res = $discord->validateCode($_GET['code']);
if(!$res->error) { if(!$res['error']) {
$_SESSION['access_token'] = $res->access_token; $_SESSION['access_token'] = $res['access_token'];
$_SESSION['refresh_token'] = $res->refresh_token; $_SESSION['refresh_token'] = $res['refresh_token'];
$_SESSION['expires_in'] = $res->expires_in; $_SESSION['expires_in'] = $res['expires_in'];
$guilds = $discord->getGuilds($res->access_token); $guilds = $discord->getGuilds($res['access_token']);
if(!in_array('', $guilds)) { $guildIds = array();
foreach ($guilds as $guild) {
$guildIds[] = $guild['id'];
}
if(!in_array('1127731341283307520', $guildIds)) {
echo json_encode(array( echo json_encode(array(
'error' => true, 'error' => true,
'error_description' => 'You are not in the CRSS guild.' 'error_description' => 'You are not in the CRSS guild.'
)); ));
} else { } else {
$_SESSION['user'] = $discord->getUser($res->access_token); $_SESSION['user'] = $discord->getUser($res['access_token']);
header('Location: /'); header('Location: /');
} }

View file

@ -67,7 +67,7 @@
} }
function getUser($token): array { function getUser($token): array {
$res = $this->curl->newRequest('get', '/users/@me') $res = $this->curl->newRequest('get', 'https://discord.com/api/v10/users/@me')
->setHeader('Authorization', 'Bearer ' . $token) ->setHeader('Authorization', 'Bearer ' . $token)
->send(); ->send();
@ -75,7 +75,7 @@
} }
function getGuilds($token): array { function getGuilds($token): array {
$res = $this->curl->newRequest('get', '/users/@me/guilds') $res = $this->curl->newRequest('get', 'https://discord.com/api/v10/users/@me/guilds')
->setHeader('Authorization', 'Bearer ' . $token) ->setHeader('Authorization', 'Bearer ' . $token)
->send(); ->send();