You are here

function hook_openid_connect_userinfo_claim_alter in OpenID Connect / OAuth client 2.x

Same name and namespace in other branches
  1. 8 openid_connect.api.php \hook_openid_connect_userinfo_claim_alter()

Userinfo claim alter hook.

This hook runs for every IdP provided userinfo claim mapped to a user property, just before the OpenID Connect module maps its value to the user property.

A popular use for this hook is preprocessing claim values from a certain IdP to match the property type of the target user property.

Parameters

mixed $claim_value: The claim value.

array $context: An context array containing:

  • claim: The current claim.
  • property_name: The property the claim is mapped to.
  • property_type: The property type the claim is mapped to.
  • userinfo_mapping: The complete userinfo mapping.
  • tokens: Array of original tokens.
  • user_data: Array of user and session data from the ID token.
  • userinfo: Array of user information from the userinfo endpoint.
  • plugin_id: The plugin identifier.
  • sub: The remote user identifier.
  • is_new: Whether the account was created during authorization.
1 invocation of hook_openid_connect_userinfo_claim_alter()
OpenIDConnect::saveUserinfo in src/OpenIDConnect.php
Save user profile information into a user account.

File

./openid_connect.api.php, line 213
Documentation for OpenID Connect module APIs.

Code

function hook_openid_connect_userinfo_claim_alter(&$claim_value, array $context) {

  // Alter only, when the claim comes from the 'generic' identity provider and
  // the property is 'telephone'.
  if ($context['plugin_id'] != 'generic' || $context['property_name'] != 'telephone') {
    return;
  }

  // Replace international number indicator with double zero.
  $claim_value = str_replace('+', '00', $claim_value);
}