Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update in accordance with discord changes #1135

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/Discord/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function getCodeFields($state = null)
{
$fields = parent::getCodeFields($state);

if (! $this->consent) {
if (!$this->consent) {
$fields['prompt'] = 'none';
}

Expand Down Expand Up @@ -82,7 +82,7 @@ protected function getUserByToken($token)
'https://discord.com/api/users/@me',
[
RequestOptions::HEADERS => [
'Authorization' => 'Bearer '.$token,
'Authorization' => 'Bearer ' . $token,
],
]
);
Expand Down Expand Up @@ -115,11 +115,13 @@ protected function formatAvatar(array $user)
protected function mapUserToObject(array $user)
{
return (new User())->setRaw($user)->map([
'id' => $user['id'],
'nickname' => $user['username'].($user['discriminator'] !== '0' ? '#'.$user['discriminator'] : ''),
'name' => $user['username'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the name field here would be a breaking change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to dd the username field in addition, but they can always use getRaw to get the other fields.

'email' => $user['email'] ?? null,
'avatar' => $this->formatAvatar($user),
'id' => $user['id'],
'nickname' => $user['username'].($user['discriminator'] !== '0' ? '#'.$user['discriminator'] : '')
'username' => $user['username'],
'discriminator' => $user['discriminator'] ?? null,
'global_name' => $user['global_name'],
'email' => $user['email'] ?? null,
'avatar' => $this->formatAvatar($user),
]);
}

Expand Down
22 changes: 13 additions & 9 deletions src/Discord/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ Please see the [Base Installation Guide](https://socialiteproviders.com/usage/),
### Add configuration to `config/services.php`

```php
'discord' => [
'client_id' => env('DISCORD_CLIENT_ID'),
'client_secret' => env('DISCORD_CLIENT_SECRET'),
'discord' => [
'client_id' => env('DISCORD_CLIENT_ID'),
'client_secret' => env('DISCORD_CLIENT_SECRET'),
'redirect' => env('DISCORD_REDIRECT_URI'),

// optional
'allow_gif_avatars' => (bool)env('DISCORD_AVATAR_GIF', true),
'avatar_default_extension' => env('DISCORD_EXTENSION_DEFAULT', 'png'), // only pick from jpg, png, webp
Expand Down Expand Up @@ -47,8 +47,12 @@ return Socialite::driver('discord')->redirect();

### Returned User fields

- ``id``
- ``nickname``
- ``name``
- ``email``
- ``avatar``
You'll find all the information about the fields currently being returned on the [Discord Developer Portal - Users Resource](https://discord.com/developers/docs/resources/user).

- `id` : The user's id (snowflake).
- `nickname` : The user's name with discriminator (name#0000).
- `username` : The user's username (name).
- `discriminator` : The user's Discord-tag (0000).
- `global_name` : The user's display name, if it is set (Amazing Name).
- `email` : The user's email ([email protected]).
- `avatar` : The user's avatar URL.
Loading