mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-22 13:09:44 +05:30
Remove getScopes function and use validateScopes instead
This commit is contained in:
parent
50ab9dd8ac
commit
322b55eddf
@ -242,13 +242,13 @@ abstract class AbstractGrant implements GrantTypeInterface
|
|||||||
*/
|
*/
|
||||||
public function validateScopes($scopes, $redirectUri = null)
|
public function validateScopes($scopes, $redirectUri = null)
|
||||||
{
|
{
|
||||||
$scopesList = array_filter(explode(self::SCOPE_DELIMITER_STRING, trim($scopes)), function ($scope) {
|
if (!is_array($scopes)) {
|
||||||
return !empty($scope);
|
$scopes = $this->convertScopesQueryStringToArray($scopes);
|
||||||
});
|
}
|
||||||
|
|
||||||
$validScopes = [];
|
$validScopes = [];
|
||||||
|
|
||||||
foreach ($scopesList as $scopeItem) {
|
foreach ($scopes as $scopeItem) {
|
||||||
$scope = $this->scopeRepository->getScopeEntityByIdentifier($scopeItem);
|
$scope = $this->scopeRepository->getScopeEntityByIdentifier($scopeItem);
|
||||||
|
|
||||||
if ($scope instanceof ScopeEntityInterface === false) {
|
if ($scope instanceof ScopeEntityInterface === false) {
|
||||||
@ -261,6 +261,20 @@ abstract class AbstractGrant implements GrantTypeInterface
|
|||||||
return $validScopes;
|
return $validScopes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a scopes query string to an array to easily iterate for validation.
|
||||||
|
*
|
||||||
|
* @param string $scopes
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function convertScopesQueryStringToArray($scopes)
|
||||||
|
{
|
||||||
|
return array_filter(explode(self::SCOPE_DELIMITER_STRING, trim($scopes)), function ($scope) {
|
||||||
|
return !empty($scope);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve request parameter.
|
* Retrieve request parameter.
|
||||||
*
|
*
|
||||||
|
@ -86,7 +86,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant
|
|||||||
$this->validateAuthorizationCode($authCodePayload, $client, $request);
|
$this->validateAuthorizationCode($authCodePayload, $client, $request);
|
||||||
|
|
||||||
$scopes = $this->scopeRepository->finalizeScopes(
|
$scopes = $this->scopeRepository->finalizeScopes(
|
||||||
$this->getScopes($authCodePayload),
|
$this->validateScopes($authCodePayload->scopes),
|
||||||
$this->getIdentifier(),
|
$this->getIdentifier(),
|
||||||
$client,
|
$client,
|
||||||
$authCodePayload->user_id
|
$authCodePayload->user_id
|
||||||
@ -194,32 +194,6 @@ class AuthCodeGrant extends AbstractAuthorizeGrant
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get scopes from the auth code payload.
|
|
||||||
*
|
|
||||||
* @param \stdClass $authCodePayload
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function getScopes($authCodePayload)
|
|
||||||
{
|
|
||||||
$scopes = [];
|
|
||||||
|
|
||||||
foreach ($authCodePayload->scopes as $scopeId) {
|
|
||||||
$scope = $this->scopeRepository->getScopeEntityByIdentifier($scopeId);
|
|
||||||
|
|
||||||
if ($scope instanceof ScopeEntityInterface === false) {
|
|
||||||
// @codeCoverageIgnoreStart
|
|
||||||
throw OAuthServerException::invalidScope($scopeId);
|
|
||||||
// @codeCoverageIgnoreEnd
|
|
||||||
}
|
|
||||||
|
|
||||||
$scopes[] = $scope;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $scopes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the grant identifier that can be used in matching up requests.
|
* Return the grant identifier that can be used in matching up requests.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user