-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
41 lines (37 loc) · 1.33 KB
/
Copy pathindex.php
File metadata and controls
41 lines (37 loc) · 1.33 KB
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
<?php
require_once 'discord.php';
// Replace these with your Discord application credentials
$clientId = 'YOUR_CLIENT_ID';
$clientSecret = 'YOUR_CLIENT_SECRET'; #
$redirectUri = 'YOUR_REDIRECT_URL';
$discordSSO = new DiscordSSO($clientId, $clientSecret, $redirectUri);
if (isset($_GET['code'])) {
$accessToken = $discordSSO->getAccessToken($_GET['code']);
if ($accessToken) {
$userInfo = $discordSSO->getUserInfo($accessToken);
print_r($userInfo);
} else {
echo 'Error: Failed to obtain access token.';
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Discord SSO Example</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<body>
<?php if (isset($userInfo)): ?>
<h1>You are logged in <?= $userInfo['username'] ?></h1>
<?php else: ?>
<h1>Discord SSO Example</h1>
<a href="<?= $discordSSO->getLoginUrl() ?>" class="btn btn-primary">Log in with Discord</a>
<?php endif; ?>
</body>
</html>