teamreflex / oauth2-discord

OAuth2 client for authenticating with the Discord API servers
MIT License
61 stars 26 forks source link

$user->guilds returns an object with all values being null #6

Closed Tsumiki-Chan closed 8 years ago

Tsumiki-Chan commented 8 years ago

When you call $user->guilds you'll get a couple of objects in which all values are NULL.

object(Illuminate\Support\Collection)#45 (1) { ["items":protected]=> array(2) { [0]=> object(Discord\OAuth\Parts\Guild)#48 (5) { ["id"]=> NULL ["name"]=> NULL ["icon"]=> NULL ["owner"]=> NULL ["permissions"]=> NULL } [1]=> object(Discord\OAuth\Parts\Guild)#41 (5) { ["id"]=> NULL ["name"]=> NULL ["icon"]=> NULL ["owner"]=> NULL ["permissions"]=> NULL } } }

chonsser commented 8 years ago

Same.

Tsumiki-Chan commented 8 years ago

Just a small update on this one. You have to request the "guilds" scope which is not requested by default. Plus you can't change the scopes using this small "api". You'll have to change the getDefaultScopes function in order to get the required privileges.

It still shouldn't return objects with all Items being null tho. I'd fix up this class but unfortunately I haven't got the time for it atm.

davidcole1340 commented 8 years ago

By default the library only requests identify and email because this is basic OAuth2 information, if you need guilds you will need to pass through the scopes when you generate the authorization URL:

$provider->getAuthorizationUrl([
    'scope' => [
        'identify',
        'email',
        'guilds',
    ],
]);
chonsser commented 8 years ago

@uniquoooo still nothing. I use this code to generate the authorization url with the guilds scope (and it works, I get the authorization url with these scopes)

$this->get('oauth2.registry')
        ->getClient('discord')
        ->redirect(['guilds','identify','email']);

And using this code to get the user's guilds:

$client = $this->get('oauth2.registry')
            ->getClient('discord');
            $user = $client->fetchUser();
            var_dump($user->getGuildsAttribute());

I receive: private 'guilds' => string '[{},{},{},{},{},{},{}]' (length=22)

Tsumiki-Chan commented 8 years ago

Still it shouldnt return obects with all values being null, should it?

Tsumiki-Chan commented 8 years ago

@chonsser Wrong usage:

It's $user->guilds