diff --git a/classes/loginflow/authcode.php b/classes/loginflow/authcode.php index 2404e77..d4aca1d 100644 --- a/classes/loginflow/authcode.php +++ b/classes/loginflow/authcode.php @@ -327,13 +327,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); } diff --git a/db/upgrade.php b/db/upgrade.php index 933e57e..28dc280 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -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; } diff --git a/version.php b/version.php index 4782d39..734a8dd 100644 --- a/version.php +++ b/version.php @@ -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;