You are here

function openid_connect_save_userinfo in OpenID Connect / OAuth client 7

Same name and namespace in other branches
  1. 8 openid_connect.module \openid_connect_save_userinfo()

Saves user profile information into a user account.

2 calls to openid_connect_save_userinfo()
openid_connect_complete_authorization in ./openid_connect.module
Complete the authorization after tokens have been retrieved.
openid_connect_connect_current_user in ./openid_connect.module
Connect the current user's account to an external provider.

File

./openid_connect.module, line 225
A pluggable client implementation for the OpenID Connect protocol.

Code

function openid_connect_save_userinfo($account, $userinfo) {
  $account_wrapper = entity_metadata_wrapper('user', $account);
  $properties = $account_wrapper
    ->getPropertyInfo();
  $properties_skip = _openid_connect_user_properties_to_skip();
  foreach ($properties as $property_name => $property) {
    if (isset($properties_skip[$property_name])) {
      continue;
    }
    $claim = variable_get('openid_connect_userinfo_mapping_property_' . $property_name, NULL);
    if ($claim && isset($userinfo[$claim])) {

      // Set the user property, while ignoring exceptions from invalid values.
      try {
        $account_wrapper->{$property_name} = $userinfo[$claim];
      } catch (EntityMetadataWrapperException $e) {
        watchdog_exception('openid_connect', $e);
      }
    }
  }

  // Save the display name additionally in the user account 'data', for use in
  // openid_connect_username_alter().
  if (isset($userinfo['name'])) {
    $account->data['oidc_name'] = $userinfo['name'];
  }
  $account_wrapper
    ->save();

  // Fetch and save user picture from the login provider.
  if (variable_get('user_pictures') && variable_get('openid_connect_user_pictures', TRUE) && !empty($userinfo['picture'])) {
    openid_connect_save_user_picture($account, $userinfo['picture']);
  }
}