dev-master
9999999-devA Discord provider for the League Oauth2 client
MIT
The Requires
The Development Requires
discord oauth2 provider thephpleague
Wallogit.com
2017 © Pedro Peláez
A Discord provider for the League Oauth2 client
This is a Discord provider for use with the PHP League's OAuth2 client., (*1)
To install the provider use Composer:, (*2)
composer require psecio/oauth2-discord
The code below is an example of how to use the library to make an OAuth connection to the Discord service, authorizing it for your account. By default it will request these scopes:, (*3)
identityemailmessages.readguildsSee this documentation for more about scopes., (*4)
'client-id',
'clientSecret' => 'client-secret',
'redirectUri' => 'http://yoursite.com/callback'
]);
if (!isset($_GET['code'])) {
// If we don't have a code yet, we need to make the link
echo 'Link to Discord';
} else {
// If we do have a code, use it to get a token
$accessToken = $provider->getAccessToken('authorization_code', [
'code' => $_GET['code']
]);
$user = $provider->getResourceOwner($accessToken);
/**
* User object contains:
* - username
* - verified
* - mfa_enabled
* - id
* - avatar
*/
}
?>
This library can also be used to get information from the API once an authenticated request has been made. This process requires a class that implements the Psecio\DiscordPHP\ConnectorInterface and defines a getToken() method. This method should return the current OAuth2 token and can then be used with the Manager class. For example:, (*5)
If all goes well (and the token isn't expired or anything odd like that) you should now be able to get information from the API using helper methods. For example, to get all of the guilds for the currently linked user, you can just use the guilds property:, (*6)
guilds;
foreach ($guilds as $guild) {
echo $guild->name;
}
?>
guilds: list of current user's guildsuser: information about the current userA Discord provider for the League Oauth2 client
MIT
discord oauth2 provider thephpleague