function hook_simple_oauth_oidc_claims_alter in Simple OAuth (OAuth2) & OpenID Connect 5.x
Allow injecting custom claims to the OpenID Connect responses.
This will allow sites to connect their custom implementations and data model to the different claims supported by OpenID Connect.
Parameters
array $private_claims: The private claims array to be altered.
array $context: Additional information relevant to the custom claims. It contains:
- 'account': The TokenAuthUserInterface object decorating the user.
- 'claims': The claim names to serve to the users. If you add new claims you will need to add them in your service container under the key 'simple_oauth.openid.claims'.
See also
\Drupal\simple_oauth\Entities\AccessTokenEntity::convertToJWT()
Related topics
1 invocation of hook_simple_oauth_oidc_claims_alter()
- UserClaimsNormalizer::getClaimsFromAccount in src/
Normalizer/ UserClaimsNormalizer.php - Gets the claims for a given user.
File
- ./
simple_oauth.api.php, line 50 - Hooks specific to the Simple OAuth module.
Code
function hook_simple_oauth_oidc_claims_alter(array &$claim_values, array &$context) {
$account = $context['account'];
assert($account instanceof UserInterface);
$value = $account
->get('field_phone_number')
->getValue();
$claim_values['phone_number'] = $value[0]['value'] ?? NULL;
}