Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove @domain.com from username at account creation #2305

Conversation

amorrowbellarmine
Copy link
Contributor

@amorrowbellarmine amorrowbellarmine commented Jun 13, 2023

This is part of an alternative solution to the request for using the sAMAccountname from AD.
#2157
#2212

This pull requests add an option to use the split UPN for the username during new Moodle account creation rather than the full UPN. This is useful if there is a 3rd party integration that relies on the username to be the sAMAccountname format, as seen in the linked issue.

The usersync code of the o365 plugin already has a function where it splits the user's UPN and matches it to a Moodle username.

$upnsplit = explode('@', $upnlower);
if (!empty($upnsplit[0])) {
$aadusers[$i]['upnsplit0'] = $upnsplit[0];
$usernames[] = $upnsplit[0];
}

if (!isset($existingusers[$aaduser['upnlower']]) && !isset($existingusers[$aaduser['upnsplit0']]) &&
!isset($existingusers[$aaduser['convertedupn']])) {
$this->sync_new_user($aadsync, $aaduser, isset($aadsync['guestsync']));
} else {
$existinguser = null;
if (isset($existingusers[$aaduser['upnlower']])) {
$existinguser = $existingusers[$aaduser['upnlower']];
$exactmatch = true;
} else if (isset($existingusers[$aaduser['upnsplit0']])) {
$existinguser = $existingusers[$aaduser['upnsplit0']];
$exactmatch = strlen($aaduser['upnsplit0']) >= $switchauthminupnsplit0;
} else if (isset($existingusers[$aaduser['convertedupn']])) {
$existinguser = $existingusers[$aaduser['convertedupn']];
$exactmatch = true;
}

This is useful when 3rd party Moodle integration require the Moodle username to be in sAMAccountname format.
@weilai-irl
Copy link
Collaborator

@amorrowbellarmine

The latest release of the plugin from yesterday introduced a new feature to allow site admins to choose the binding access or ID token claims to be used as Moodle username. This is how we imagine it should work - if you want to use the part without the domain part of the UPN as Moodle username, make sure this value presents in a token claim (either default or optional), and use the feature introduced to achieve it.

Please try it out.

Regards,
Lai

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants