-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprocess.php
57 lines (52 loc) · 1.75 KB
/
process.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
if((empty($_GET["action"])) and (empty($_GET["code"]))){
header("Location: ./");
die();
}elseif(($_GET["action"] != "logout") and ($_GET["action"] != "login") and (empty($_GET["code"]))){
header("Location: ./");
die();
}
require_once("functions.php");
require_once("navbar.php");
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('max_execution_time', 300);
error_reporting(E_ALL);
define('OAUTH2_CLIENT_ID', ''); // OAUTH2 CLIENT ID for your bot.
define('OAUTH2_CLIENT_SECRET', ''); // OAUTH2 CLIENT SECRET TOKEN for your bot.
$tokenURL = 'https://discord.com/api/oauth2/token';
$apiURLBase = 'https://discord.com/api/users/@me';
$redirectURL = $url . '/process.php';
if (get('action') == 'login'){
$params = array(
'client_id' => OAUTH2_CLIENT_ID,
'redirect_uri' => $redirectURL,
'response_type' => 'code',
'scope' => 'identify guilds'
);
header('Location: https://discordapp.com/api/oauth2/authorize' . '?' . http_build_query($params));
die();
}
if(get('action') == 'logout'){
session_destroy();
unset($_SESSION["user"]);
unset($_SESSION["access_token"]);
header("Location: index.php");
}
if (get('code')){
$token = apiRequest($tokenURL, array(
"grant_type" => "authorization_code",
'client_id' => OAUTH2_CLIENT_ID,
'client_secret' => OAUTH2_CLIENT_SECRET,
'redirect_uri' => $redirectURL,
'code' => get('code')
));
$logout_token = $token->access_token;
$_SESSION['access_token'] = $token->access_token;
header('Location: ' . $_SERVER['PHP_SELF']);
}
if (session('access_token')){
$_SESSION["user"] = session('access_token');
header("Location: profile.php");
}
?>