diff --git a/composer.json b/composer.json index 88077ae..442cafa 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "require": { "php": "^7.2 || ^8.0", "illuminate/support": "^6.0 || ^7.0 || ^8.0", - "laravel/socialite": "~4.0 || ~5.0" + "laravel/socialite": "^5.5" }, "require-dev": { "mockery/mockery": "^1.2", diff --git a/src/OAuth2/AbstractProvider.php b/src/OAuth2/AbstractProvider.php index 6e5b319..97bbb3c 100644 --- a/src/OAuth2/AbstractProvider.php +++ b/src/OAuth2/AbstractProvider.php @@ -19,12 +19,13 @@ abstract class AbstractProvider extends BaseProvider implements ProviderInterfac protected $credentialsResponseBody; /** - * @param string $providerName + * @param string $providerName + * * @return string */ public static function serviceContainerKey($providerName) { - return SocialiteWasCalled::SERVICE_CONTAINER_PREFIX.$providerName; + return SocialiteWasCalled::SERVICE_CONTAINER_PREFIX . $providerName; } /** @@ -50,15 +51,16 @@ public function user() } return $user->setToken($token) - ->setRefreshToken($this->parseRefreshToken($response)) - ->setExpiresIn($this->parseExpiresIn($response)) - ->setApprovedScopes($this->parseApprovedScopes($response)); + ->setRefreshToken($this->parseRefreshToken($response)) + ->setExpiresIn($this->parseExpiresIn($response)) + ->setApprovedScopes($this->parseApprovedScopes($response)); } /** * Get the access token from the token response body. * - * @param array $body + * @param array $body + * * @return string */ protected function parseAccessToken($body) @@ -69,7 +71,8 @@ protected function parseAccessToken($body) /** * Get the refresh token from the token response body. * - * @param array $body + * @param array $body + * * @return string */ protected function parseRefreshToken($body) @@ -80,7 +83,8 @@ protected function parseRefreshToken($body) /** * Get the expires in from the token response body. * - * @param array $body + * @param array $body + * * @return string */ protected function parseExpiresIn($body) @@ -91,11 +95,22 @@ protected function parseExpiresIn($body) /** * Get the approved scopes from the token response body. * - * @param array $body + * @param array $body + * * @return array */ protected function parseApprovedScopes($body) { + $scopesRaw = Arr::get($body, 'scope', null); + + if (!is_array($scopesRaw) && !is_string($scopesRaw)) { + return []; + } + + if (is_array($scopesRaw)) { + return $scopesRaw; + } + return explode($this->scopeSeparator, Arr::get($body, 'scope', '')); } }