protected function ScopeRepository::addRoleToScopes in Simple OAuth (OAuth2) & OpenID Connect 8.2
Same name and namespace in other branches
- 8.4 src/Repositories/ScopeRepository.php \Drupal\simple_oauth\Repositories\ScopeRepository::addRoleToScopes()
- 8.3 src/Repositories/ScopeRepository.php \Drupal\simple_oauth\Repositories\ScopeRepository::addRoleToScopes()
- 5.x src/Repositories/ScopeRepository.php \Drupal\simple_oauth\Repositories\ScopeRepository::addRoleToScopes()
Add an additional scope if it's not present.
Parameters
\League\OAuth2\Server\Entities\ScopeEntityInterface[] $scopes: The list of scopes.
string $additional_role_id: The role ID to add as a scope.
Return value
\League\OAuth2\Server\Entities\ScopeEntityInterface[] The modified list of scopes.
1 call to ScopeRepository::addRoleToScopes()
- ScopeRepository::finalizeScopes in src/
Repositories/ ScopeRepository.php - This will remove any role that is not associated to the identified user and add all the roles configured in the client.
File
- src/
Repositories/ ScopeRepository.php, line 101
Class
Namespace
Drupal\simple_oauth\RepositoriesCode
protected function addRoleToScopes(array $scopes, $additional_role_id) {
$role_storage = $this->entityTypeManager
->getStorage('user_role');
// Only add the role if it's not already in the list.
$found = array_filter($scopes, function (ScopeEntityInterface $scope) use ($additional_role_id) {
return $scope
->getIdentifier() == $additional_role_id;
});
if (empty($found)) {
// If it's not there, then add the authenticated role.
$additional_role = $role_storage
->load($additional_role_id);
array_push($scopes, $this
->scopeFactory($additional_role));
}
return $scopes;
}