Skip to content

Commit

Permalink
fix: set approved scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
atymic committed May 4, 2024
1 parent 6dd81fc commit dbedc1e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
33 changes: 24 additions & 9 deletions src/OAuth2/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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', ''));
}
}

0 comments on commit dbedc1e

Please sign in to comment.