1. Go to this page and download the library: Download romitou/oauth2-discord library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
romitou / oauth2-discord example snippets
n_start();
$discordProvider = new \Romitou\OAuth2\Client\DiscordProvider([
'clientId' => '', // The ID of your application
'clientSecret' => '', // The secret of your application
'redirectUri' => '', // The callback URI where the user will be redirected
'scopes' => [], // The scopes you want (e.g. ['identify', 'email'])
'state' => '' // Optional, the state of the provider
]);
if (isset($_GET['code'])) {
if ($_SESSION['oauth2_state'] !== $_GET['state'])
exit('The returned state doesn\'t match with your local state.');
$discordToken = $discordProvider->getAccessToken('authorization_code', [
'code' => $_GET['code']
]);
$discordUser = $discordProvider->getResourceOwner($discordToken);
// Now, you will be able to retrieve user's informations.
echo 'Your token is ' . $discordToken->getToken();
echo 'Your username is ' . $discordUser->getUsername();
} else {
$oauthUrl = $discordProvider->getAuthorizationUrl();
$_SESSION['oauth2_state'] = $discordProvider->getState();
header('Location: ' . $oauthUrl);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.