diff --git a/composer.json b/composer.json index 297bfd9..0b7528f 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ "require": { "php": "^8.0", "illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0", - "laravel/socialite": "^5.2" + "laravel/socialite": "^5.5" }, "require-dev": { "mockery/mockery": "^1.2", diff --git a/src/OAuth2/AbstractProvider.php b/src/OAuth2/AbstractProvider.php index c32f5f7..cff100b 100644 --- a/src/OAuth2/AbstractProvider.php +++ b/src/OAuth2/AbstractProvider.php @@ -26,12 +26,13 @@ abstract class AbstractProvider extends BaseProvider implements ProviderInterfac protected $user; /** - * @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; } /** @@ -61,14 +62,16 @@ public function user() } return $this->user->setToken($token) - ->setRefreshToken($this->parseRefreshToken($response)) - ->setExpiresIn($this->parseExpiresIn($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) @@ -79,7 +82,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) @@ -90,11 +94,34 @@ 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) { return Arr::get($body, 'expires_in'); } + + /** + * Get the approved scopes from the token response 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', '')); + } }