There is currently no way to change which property is being used to get the username. This module gets the displayName and uses it as the name (username) property, but openid_connect checks: $candidates = array('preferred_username', 'name');. There is not currently a way to set the preferred_username before the username is set in retrieveUserInfo in OpenidConnectWindowsAadClient.class.php.

I propose adding a hook to alter the user info. See patch file.

The above hook has already been added.

This issue is still open because a .patch file was added by mistake, and the new hook was not documented in the .api.php file. See #7.

Comments

solideogloria created an issue. See original summary.

tomvv’s picture

Yep,I am aware of this - sometimes - needed functionality, had this added to an earlier version of the module as well. I will apply your patch, thank you.

tomvv’s picture

Status: Active » Fixed

  • tomvv committed dcb3c69 on 7.x-1.x authored by solideogloria
    Issue #3021049 by solideogloria: No way to alter userinfo before getting...
solideogloria’s picture

Though it's been a while, I realize I didn't add an entry to the .api.php file for this hook. Should there be one?

tomvv’s picture

You can add if you like, but just let me know if you want me to do it as a compensation for the long waiting.

solideogloria’s picture

Status: Fixed » Needs review
StatusFileSize
new1.71 KB

Here's the patch to add the .api.php. I also removed the .patch file you committed in your previous commit for this issue.

tomvv’s picture

Ah ok, thanks @solideogloria! I will check the patch asap.

solideogloria’s picture

Status: Needs review » Reviewed & tested by the community

Just a reminder that the fix was committed, but not the .api.php file.

solideogloria’s picture

Issue summary: View changes
glajman’s picture

Was this patch applied to the 8/9.x version of this module ?

I cant seem to find this functionality there as the issue is the same for version 8/9.x.

Any help is appreciated.

-G

solideogloria’s picture

Here is how to do it in Drupal 8+, I think:

use Drupal\user\UserInterface;

/**
 * Implements hook_openid_connect_userinfo_save().
 */
function MY_MODULE_openid_connect_userinfo_save(UserInterface $account, array $context): void {
  // Use the actual username for the username, instead of the display name.
  preg_match('/^(.+)@([^@]+)$/i', $context['user_data']['upn'], $matches);
  if (!isset($matches[1])) {
    return;
  }
  $account->setUsername($matches[1]);
}

Note that in the above example, I set the username from the first part of the email address.

batigolix’s picture

Status: Reviewed & tested by the community » Closed (won't fix)