Remove getScopes function and use validateScopes instead

This commit is contained in:
sephster 2018-10-13 16:11:44 +01:00
parent 50ab9dd8ac
commit 322b55eddf
No known key found for this signature in database
GPG Key ID: 077754CA23023F4F
2 changed files with 19 additions and 31 deletions

View File

@ -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.
* *

View File

@ -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.
* *