You are here

protected function OpenIdConnectScopeRepository::addRoleToScopes in Simple OAuth (OAuth2) & OpenID Connect 5.x

Add an additional scope if it's not present.

Parameters

\League\OAuth2\Server\Entities\ScopeEntityInterface[] $scopes: The list of scopes.

\League\OAuth2\Server\Entities\ScopeEntityInterface $new_scope: The additional scope.

Return value

\League\OAuth2\Server\Entities\ScopeEntityInterface[] The modified list of scopes.

1 call to OpenIdConnectScopeRepository::addRoleToScopes()
OpenIdConnectScopeRepository::finalizeScopes in src/OpenIdConnect/OpenIdConnectScopeRepository.php

File

src/OpenIdConnect/OpenIdConnectScopeRepository.php, line 98

Class

OpenIdConnectScopeRepository
OpenID Connect scope repository decorator.

Namespace

Drupal\simple_oauth\OpenIdConnect

Code

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;
}