Add means to set default scopes for grants

This commit is contained in:
Andrew Millington
2017-10-18 22:08:41 +01:00
parent c70451abd5
commit c996b66528
7 changed files with 42 additions and 19 deletions

View File

@@ -56,6 +56,11 @@ abstract class AbstractGrant implements GrantTypeInterface
*/
protected $scopeRepository;
/**
* @var string
*/
protected $defaultScope = '';
/**
* @var AuthCodeRepositoryInterface
*/
@@ -105,6 +110,14 @@ abstract class AbstractGrant implements GrantTypeInterface
$this->scopeRepository = $scopeRepository;
}
/**
* @param string $scope
*/
public function setDefaultScope($scope)
{
$this->defaultScope = $scope;
}
/**
* @param RefreshTokenRepositoryInterface $refreshTokenRepository
*/
@@ -211,10 +224,8 @@ abstract class AbstractGrant implements GrantTypeInterface
*
* @return ScopeEntityInterface[]
*/
public function validateScopes(
$scopes,
$redirectUri = null
) {
public function validateScopes($scopes, $redirectUri = null)
{
$scopesList = array_filter(
explode(self::SCOPE_DELIMITER_STRING, trim($scopes)),
function ($scope) {
@@ -222,7 +233,8 @@ abstract class AbstractGrant implements GrantTypeInterface
}
);
$scopes = [];
$validScopes = [];
foreach ($scopesList as $scopeItem) {
$scope = $this->scopeRepository->getScopeEntityByIdentifier($scopeItem);
@@ -230,10 +242,14 @@ abstract class AbstractGrant implements GrantTypeInterface
throw OAuthServerException::invalidScope($scopeItem, $redirectUri);
}
$scopes[] = $scope;
$validScopes[] = $scope;
}
return $scopes;
if (empty($validScopes)) {
throw OAuthServerException::missingScope($redirectUri);
}
return $validScopes;
}
/**