Skip to content

Commit

Permalink
set the approved scopes into User (#229)
Browse files Browse the repository at this point in the history
Co-authored-by: Lindsay Snider <[email protected]>
Co-authored-by: Lindsay Snider <[email protected]>
  • Loading branch information
3 people authored May 4, 2024
1 parent a67f194 commit dea5190
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
41 changes: 34 additions & 7 deletions src/OAuth2/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

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

0 comments on commit dea5190

Please sign in to comment.