You are here

function hook_oauth2_server_user_claims_alter in OAuth2 Server 7

Same name and namespace in other branches
  1. 8 oauth2_server.api.php \hook_oauth2_server_user_claims_alter()
  2. 2.0.x oauth2_server.api.php \hook_oauth2_server_user_claims_alter()

Alter user claims about the provided account.

The provided claims can be included in the id_token and / or returned from the /oauth2/UserInfo endpoint.

Groups of claims are returned based on the requested scopes. No group is required, and no claim is required.

Parameters

array &$claims: Existing claims provided by OAuth2 Server or other modules.

object $account: The user account for which claims should be returned.

array $requested_scopes: The requested scopes.

See also

hook_oauth2_server_user_claims()

http://openid.net/specs/openid-connect-core-1_0.html#ScopeClaims

1 function implements hook_oauth2_server_user_claims_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

oauth2_server_test_oauth2_server_user_claims_alter in tests/oauth2_server_test.module
Implements hook_oauth2_server_user_claims_alter().
1 invocation of hook_oauth2_server_user_claims_alter()
Storage::getUserClaims in lib/Drupal/oauth2_server/Storage.php

File

./oauth2_server.api.php, line 63
Hooks provided by the OAuth2 Server module.

Code

function hook_oauth2_server_user_claims_alter(&$claims, $account, $requested_scopes) {
  $wrapper = entity_metadata_wrapper('user', $account);

  // Example: add the birthday from a custom field, if the 'profile' scope is
  // requested.
  if (in_array('profile', $requested_scopes) && !empty($wrapper->field_birthday)) {
    $claims['birthdate'] = date('0000-m-d', strtotime($wrapper->field_birthday
      ->value()));
  }

  // Example: add the phone number from a custom field, if the 'phone' scope is
  // requested.
  if (in_array('phone', $requested_scopes) && !empty($wrapper->field_phone)) {
    $claims += array(
      'phone_number' => date('0000-m-d', strtotime($wrapper->field_phone
        ->value())),
      'phone_number_verified' => FALSE,
    );
  }
}