SocialiteProviders / Providers

A Collection of Providers for Laravel Socialite
https://socialiteproviders.com
MIT License
487 stars 435 forks source link

Fix Twitch TypeError when refreshing tokens #1186

Closed nickbeen closed 3 months ago

nickbeen commented 3 months ago

Refreshing tokens with Twitch will result in a TypeError. Socialite expects the scope to be returned as a string, but Twitch will return the scope in an array.

Fix error

Use the scope array directly instead of using explode().

Reproduce error

Socialite::driver('twitch')->refreshToken($refreshToken);

Example response:

{
  "access_token": "1ssjqsqfy6bads1ws7m03gras79zfr",
  "refresh_token": "eyJfMzUtNDU0OC4MWYwLTQ5MDY5ODY4NGNlMSJ9%asdfasdf=",
  "scope": [
    "channel:read:subscriptions",
    "channel:manage:polls"
  ],
  "token_type": "bearer"
}

Result:

   TypeError

  explode(): Argument #2 ($string) must be of type string, array given

  at vendor/laravel/socialite/src/Two/AbstractProvider.php:357
    353▕         return new Token(
    354▕             Arr::get($response, 'access_token'),
    355▕             Arr::get($response, 'refresh_token'),
    356▕             Arr::get($response, 'expires_in'),
  ➜ 357▕             explode($this->scopeSeparator, Arr::get($response, 'scope', ''))
    358▕         );
    359▕     }
    360▕
    361▕     /**