You are here

public function OpenidConnectWindowsAadClient::retrieveUserInfo in OpenID Connect Microsoft Azure Active Directory client 7

Overrides OpenIDConnectClientBase::retrieveUserInfo().

@todo -- map the Graph attribute names on userinfo, as they are different.

Overrides OpenIDConnectClientBase::retrieveUserInfo

File

plugins/openid_connect_client/windows_aad/OpenidConnectWindowsAadClient.class.php, line 122
OpenID Connect client for Windows Azure AD.

Class

OpenidConnectWindowsAadClient
Class OpenidConnectWindowsAadClient adds the client to OpenID Connect.

Code

public function retrieveUserInfo($access_token) {

  // Determine if we use Graph API or default Openid Userinfo as this will
  // affect the data we collect and use in the Userinfo array.
  switch ($this
    ->getSetting('userinfo_graph_api_wa')) {
    case 1:
      $userinfo = $this
        ->buildUserinfo($access_token, 'https://graph.windows.net/me?api-version=1.6', 'userPrincipalName', 'displayName');
      break;
    default:
      $endpoints = $this
        ->getEndpoints();
      $userinfo = $this
        ->buildUserinfo($access_token, $endpoints['userinfo'], 'upn', 'name');
      break;
  }
  drupal_alter('openid_connect_windows_aad_userinfo', $userinfo);

  // Check to see if we have changed email data, openid_connect doesn't
  // give us the possibility to add a mapping for it, so we do the change
  // now, first checking if this is wanted by checking the setting for it.
  if ($this
    ->getSetting('userinfo_update_email') == 1) {
    $user = user_load_by_name($userinfo['name']);
    if ($user && $user->mail != $userinfo['email']) {
      $edit = array(
        'mail' => $userinfo['email'],
      );
      user_save($user, $edit);
    }
  }
  return $userinfo;
}