Skip to content

Commit

Permalink
Handle empty binding username claim configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
weilai-irl committed Nov 27, 2024
1 parent 3139219 commit 4a6b489
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion auth/oidc/classes/form/binding_username_claim.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected function definition() {
$mform->addElement(
'select',
'bindingusernameclaim',
auth_oidc_config_name_in_form('binding_username_claim'),
auth_oidc_config_name_in_form('beingusernameclaim'),
$bindingusernameoptions
);
$mform->setDefault('bindingusernameclaim', 'auto');
Expand Down
4 changes: 4 additions & 0 deletions auth/oidc/classes/loginflow/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,10 @@ protected function get_oidc_username_from_token_claim(jwt $idtoken, string $bind

if (empty($bindingusernameclaim)) {
$bindingusernameclaim = get_config('auth_oidc', 'bindingusernameclaim');
if (empty($bindingusernameclaim)) {
$bindingusernameclaim = 'auto';
set_config('bindingusernameclaim', $bindingusernameclaim, 'auth_oidc');
}
}

switch ($bindingusernameclaim) {
Expand Down
37 changes: 37 additions & 0 deletions auth/oidc/db/install.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Plugin installation script.
*
* @package auth_oidc
* @author Lai Wei <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/)
*/

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

/**
* Installation script.
*/
function xmldb_auth_oidc_install() {
// Set the default value for the bindingusernameclaim setting.
$bindingusernameclaimconfig = get_config('auth_oidc', 'bindingusernameclaim');
if (empty($bindingusernameclaimconfig)) {
set_config('bindingusernameclaim', 'auto', 'auth_oidc');
}
}
11 changes: 11 additions & 0 deletions auth/oidc/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,5 +504,16 @@ function xmldb_auth_oidc_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2024042201, 'auth', 'oidc');
}

if ($oldversion < 2024042206) {
// Set the default value for the bindingusernameclaim setting.
$bindingusernameclaimconfig = get_config('auth_oidc', 'bindingusernameclaim');
if (empty($bindingusernameclaimconfig)) {
set_config('bindingusernameclaim', 'auto', 'auth_oidc');
}

// Oidc savepoint reached.
upgrade_plugin_savepoint(true, 2024042206, 'auth', 'oidc');
}

return true;
}
2 changes: 1 addition & 1 deletion auth/oidc/lang/en/auth_oidc.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@
<div class="existing_claims">{$a}</div>';
$string['binding_username_auto'] = 'Choose automatically';
$string['binding_username_custom'] = 'Custom';
$string['binding_username_claim'] = 'Binding username claim';
$string['bindingusernameclaim'] = 'Binding username claim';
$string['customclaimname'] = 'Custom claim name';
$string['customclaimname_description'] = 'This field is used only when the <b>Binding Username Claim</b> setting is set to <b>Custom</b>.';
$string['binding_username_claim_help_ms_no_user_sync'] = 'The options for non Microsoft IdPs include:
Expand Down
2 changes: 1 addition & 1 deletion auth/oidc/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

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

$plugin->version = 2024042205;
$plugin->version = 2024042206;
$plugin->requires = 2024042200;
$plugin->release = '4.4.1';
$plugin->component = 'auth_oidc';
Expand Down

0 comments on commit 4a6b489

Please sign in to comment.