You are here

public function KnownClientsRepository::isAuthorized in Simple OAuth (OAuth2) & OpenID Connect 5.x

Same name and namespace in other branches
  1. 8.4 src/KnownClientsRepository.php \Drupal\simple_oauth\KnownClientsRepository::isAuthorized()
  2. 8.3 src/KnownClientsRepository.php \Drupal\simple_oauth\KnownClientsRepository::isAuthorized()

Checks if a given user authorized a client for a given set of scopes.

Parameters

int $uid: The user ID.

string $client_id: The client ID.

string[] $scopes: List of scopes to authorize for.

Return value

bool TRUE if the client is authorized, FALSE otherwise.

Overrides KnownClientsRepositoryInterface::isAuthorized

File

src/KnownClientsRepository.php, line 32

Class

KnownClientsRepository
Default implementation for the known clients repository.

Namespace

Drupal\simple_oauth

Code

public function isAuthorized($uid, $client_id, array $scopes) {
  $name = 'client:' . $client_id;
  $authorized_scopes = $this->userData
    ->get('simple_oauth', $uid, $name);

  // Access is allowed if all the requested scopes are part of the alrady
  // authorized scopes.
  if (is_array($authorized_scopes) && !array_diff($scopes, $authorized_scopes)) {
    return TRUE;
  }
  return FALSE;
}