Skip to content

Commit

Permalink
MSFTMPP-340: Fix logins for Azure users with uppercase characters whe…
Browse files Browse the repository at this point in the history
…n using PostgreSQL
  • Loading branch information
jamesmcq committed Feb 5, 2016
1 parent 982b9ce commit 4f214a4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion classes/loginflow/authcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,14 @@ protected function handlelogin($oidcuniqid, $authparams, $tokenparams, $idtoken)
// Use 'upn' if available for username (Azure-specific), or fall back to lower-case oidcuniqid.
$username = $idtoken->claim('upn');
if (empty($username)) {
$username = strtolower($oidcuniqid);
$username = $oidcuniqid;
}
$matchedwith = $this->check_for_matched($username);
if (!empty($matchedwith)) {
$matchedwith->aadupn = $username;
throw new \moodle_exception('errorusermatched', 'local_o365', null, $matchedwith);
}
$username = trim(\core_text::strtolower($username));
$tokenrec = $this->createtoken($oidcuniqid, $username, $authparams, $tokenparams, $idtoken);
}

Expand Down
15 changes: 15 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,20 @@ function xmldb_auth_oidc_upgrade($oldversion) {
upgrade_plugin_savepoint($result, '2015011615', 'auth', 'oidc');
}

if ($result && $oldversion < 2015011627.01) {
// Ensure the username field in auth_oidc_token is lowercase.
$authtokensrs = $DB->get_recordset('auth_oidc_token');
foreach ($authtokensrs as $authtokenrec) {
$newusername = trim(\core_text::strtolower($authtokenrec->username));
if ($newusername !== $authtokenrec->username) {
$updatedrec = new \stdClass;
$updatedrec->id = $authtokenrec->id;
$updatedrec->username = $newusername;
$DB->update_record('auth_oidc_token', $updatedrec);
}
}
upgrade_plugin_savepoint($result, '2015011627.01', 'auth', 'oidc');
}

return $result;
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2015011627;
$plugin->version = 2015011627.01;
$plugin->requires = 2014051200;
$plugin->component = 'auth_oidc';
$plugin->maturity = MATURITY_STABLE;
Expand Down

0 comments on commit 4f214a4

Please sign in to comment.