private function OpenidConnectWindowsAadClient::buildUserinfo in OpenID Connect Microsoft Azure Active Directory client 7
Helper function to do the call to the endpoint and build userinfo array.
Parameters
string $access_token: The access token.
string $url: The endpoint we want to send the request to.
string $upn: The name of the property that holds the Azure username.
string $name: The name of the property we want to map to Drupal username.
Return value
array The userinfo array or FALSE.
1 call to OpenidConnectWindowsAadClient::buildUserinfo()
- OpenidConnectWindowsAadClient::retrieveUserInfo in plugins/
openid_connect_client/ windows_aad/ OpenidConnectWindowsAadClient.class.php - Overrides OpenIDConnectClientBase::retrieveUserInfo().
File
- plugins/
openid_connect_client/ windows_aad/ OpenidConnectWindowsAadClient.class.php, line 167 - OpenID Connect client for Windows Azure AD.
Class
- OpenidConnectWindowsAadClient
- Class OpenidConnectWindowsAadClient adds the client to OpenID Connect.
Code
private function buildUserinfo($access_token, $url, $upn, $name) {
// Perform the request.
$options = array(
'method' => 'GET',
'headers' => array(
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $access_token,
),
);
$result = drupal_http_request($url, $options);
if (in_array($result->code, array(
200,
304,
))) {
$profile_data = json_decode($result->data, TRUE);
$profile_data['name'] = $profile_data[$name];
if (!isset($profile_data['email'])) {
// See if we have the Graph otherMails property and use it if available,
// if not, add the principal name as email instead, so Drupal still will
// create the user anyway.
if ($this
->getSetting('userinfo_graph_api_use_other_mails') == 1) {
if (!empty($profile_data['otherMails'])) {
// Use first occurrence of otherMails attribute.
$profile_data['email'] = current($profile_data['otherMails']);
}
}
else {
// Show message to user.
if ($this
->getSetting('hide_email_address_warning') != 1) {
drupal_set_message(t('Email address not found in UserInfo. Used username instead, please check this in your profile.'), 'warning');
}
// Write watchdog warning.
$type = 'warning';
$message = 'Email address of user @user not found in UserInfo. Used username instead, please check.';
$variables = array(
'@user' => $profile_data[$upn],
);
watchdog($type, $message, $variables);
$profile_data['email'] = $profile_data[$upn];
}
}
return $profile_data;
}
else {
drupal_set_message(t('The UserInfo cannot be retrieved. Please check your settings.'), 'error');
return FALSE;
}
}