class OpenIdConnectScopeRepository in Simple OAuth (OAuth2) & OpenID Connect 5.x
OpenID Connect scope repository decorator.
Hierarchy
- class \Drupal\simple_oauth\OpenIdConnect\OpenIdConnectScopeRepository implements \League\OAuth2\Server\Repositories\ScopeRepositoryInterface uses StringTranslationTrait
Expanded class hierarchy of OpenIdConnectScopeRepository
File
- src/
OpenIdConnect/ OpenIdConnectScopeRepository.php, line 14
Namespace
Drupal\simple_oauth\OpenIdConnectView source
class OpenIdConnectScopeRepository implements ScopeRepositoryInterface {
use StringTranslationTrait;
/**
* The inner scope repository.
*
* @var \League\OAuth2\Server\Repositories\ScopeRepositoryInterface
*/
protected $innerScopeRepository;
/**
* OpenIdConnectScopeRepository constructor.
*
* @param \League\OAuth2\Server\Repositories\ScopeRepositoryInterface $inner_scope_repository
* The inner scope repository.
*/
public function __construct(ScopeRepositoryInterface $inner_scope_repository) {
$this->innerScopeRepository = $inner_scope_repository;
}
/**
* {@inheritdoc}
*/
public function getScopeEntityByIdentifier($identifier) {
// First check if this scope exists as a role.
$role_scope = $this->innerScopeRepository
->getScopeEntityByIdentifier($identifier);
if ($role_scope) {
return $role_scope;
}
// Fall back to a fixed list of OpenID scopes.
$openid_scopes = $this
->getOpenIdScopes();
if (isset($openid_scopes[$identifier])) {
return new OpenIdConnectScopeEntity($identifier, $openid_scopes[$identifier]);
}
return NULL;
}
/**
* {@inheritdoc}
*/
public function finalizeScopes(array $scopes, $grantType, ClientEntityInterface $clientEntity, $userIdentifier = NULL) {
$finalized_scopes = $this->innerScopeRepository
->finalizeScopes($scopes, $grantType, $clientEntity, $userIdentifier);
// Make sure that the openid scopes are in the user list.
$openid_scopes = $this
->getOpenIdScopes();
foreach ($scopes as $scope) {
if (isset($openid_scopes[$scope
->getIdentifier()])) {
$finalized_scopes = $this
->addRoleToScopes($finalized_scopes, new OpenIdConnectScopeEntity($scope
->getIdentifier(), $openid_scopes[$scope
->getIdentifier()]));
}
}
return $finalized_scopes;
}
/**
* Returns fixed OpenID Connect scopes.
*
* @return array
* A list of scope names keyed by their identifier.
*/
protected function getOpenIdScopes() {
$openid_scopes = [
'openid' => $this
->t('User information'),
'profile' => $this
->t('Profile information'),
'email' => $this
->t('E-Mail'),
'phone' => $this
->t('Phone'),
'address' => $this
->t('Address'),
];
return $openid_scopes;
}
/**
* Add an additional scope if it's not present.
*
* @param \League\OAuth2\Server\Entities\ScopeEntityInterface[] $scopes
* The list of scopes.
* @param \League\OAuth2\Server\Entities\ScopeEntityInterface $new_scope
* The additional scope.
*
* @return \League\OAuth2\Server\Entities\ScopeEntityInterface[]
* The modified list of scopes.
*/
protected function addRoleToScopes(array $scopes, ScopeEntityInterface $new_scope) {
// Only add the role if it's not already in the list.
$found = array_filter($scopes, function (ScopeEntityInterface $scope) use ($new_scope) {
return $scope
->getIdentifier() == $new_scope
->getIdentifier();
});
if (empty($found)) {
// If it's not there, then add it.
array_push($scopes, $new_scope);
}
return $scopes;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OpenIdConnectScopeRepository:: |
protected | property | The inner scope repository. | |
OpenIdConnectScopeRepository:: |
protected | function | Add an additional scope if it's not present. | |
OpenIdConnectScopeRepository:: |
public | function | ||
OpenIdConnectScopeRepository:: |
protected | function | Returns fixed OpenID Connect scopes. | |
OpenIdConnectScopeRepository:: |
public | function | ||
OpenIdConnectScopeRepository:: |
public | function | OpenIdConnectScopeRepository constructor. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |