You are here

private function UserClaimsNormalizer::getClaimsFromAccount in Simple OAuth (OAuth2) & OpenID Connect 5.x

Gets the claims for a given user.

Parameters

\Drupal\Core\Session\AccountInterface $account: The user account.

Return value

array The claims key/values.

1 call to UserClaimsNormalizer::getClaimsFromAccount()
UserClaimsNormalizer::normalize in src/Normalizer/UserClaimsNormalizer.php

File

src/Normalizer/UserClaimsNormalizer.php, line 85

Class

UserClaimsNormalizer
Normalizes a user entity to extract the claims.

Namespace

Drupal\simple_oauth\Normalizer

Code

private function getClaimsFromAccount(AccountInterface $account) {
  $profile_url = $account
    ->toUrl('canonical', [
    'absolute' => TRUE,
  ])
    ->toString();
  $claim_values = [
    'sub' => $account
      ->id(),
    'name' => $account
      ->getDisplayName(),
    'preferred_username' => $account
      ->getAccountName(),
    'email' => $account
      ->getEmail(),
    'email_verified' => TRUE,
    'profile' => $profile_url,
    'locale' => $account
      ->getPreferredLangcode(),
    'zoneinfo' => $account
      ->getTimeZone(),
  ];
  if ($account instanceof EntityChangedInterface) {
    $claim_values['updated_at'] = $account
      ->getChangedTime();
  }
  $context = [
    'account' => $account,
    'claims' => $this->claims,
  ];
  $this->moduleHandler
    ->alter('simple_oauth_oidc_claims', $claim_values, $context);
  return array_intersect_key($claim_values, array_flip($this->claims));
}