diff --git a/auth/oidc/classes/form/binding_username_claim.php b/auth/oidc/classes/form/binding_username_claim.php index eeef1954b..42386222c 100644 --- a/auth/oidc/classes/form/binding_username_claim.php +++ b/auth/oidc/classes/form/binding_username_claim.php @@ -102,7 +102,12 @@ protected function definition() { throw new moodle_exception('missing_idp_type', 'auth_oidc'); } - $mform->addElement('select', 'bindingusernameclaim', auth_oidc_config_name_in_form('binding_username_claim'), $bindingusernameoptions); + $mform->addElement( + 'select', + 'bindingusernameclaim', + auth_oidc_config_name_in_form('bindingusernameclaim'), + $bindingusernameoptions + ); $mform->setDefault('bindingusernameclaim', 'auto'); $mform->addElement('static', 'bindingusernameclaim_description', '', get_string($descriptionidentifier, 'auth_oidc')); diff --git a/auth/oidc/classes/loginflow/base.php b/auth/oidc/classes/loginflow/base.php index a4896ca91..4ebf692a5 100644 --- a/auth/oidc/classes/loginflow/base.php +++ b/auth/oidc/classes/loginflow/base.php @@ -731,6 +731,10 @@ protected function get_oidc_username_from_token_claim(jwt $idtoken, string $bin if (empty($bindingusernameclaim)) { $bindingusernameclaim = get_config('auth_oidc', 'bindingusernameclaim'); + if (empty($bindingusernameclaim)) { + $bindingusernameclaim = 'auto'; + set_config('bindingusernameclaim', $bindingusernameclaim, 'auth_oidc'); + } } switch ($bindingusernameclaim) { diff --git a/auth/oidc/db/install.php b/auth/oidc/db/install.php new file mode 100644 index 000000000..768eef90f --- /dev/null +++ b/auth/oidc/db/install.php @@ -0,0 +1,35 @@ +. + +/** + * Plugin installation script. + * + * @package auth_oidc + * @author Lai Wei + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/) + */ + +/** + * 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'); + } +} diff --git a/auth/oidc/db/upgrade.php b/auth/oidc/db/upgrade.php index 28c49da0a..b71b5c70f 100644 --- a/auth/oidc/db/upgrade.php +++ b/auth/oidc/db/upgrade.php @@ -499,5 +499,16 @@ function xmldb_auth_oidc_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2023042431, 'auth', 'oidc'); } + if ($oldversion < 2023042436) { + // 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, 2023042436, 'auth', 'oidc'); + } + return true; } diff --git a/auth/oidc/lang/en/auth_oidc.php b/auth/oidc/lang/en/auth_oidc.php index 3c7ec4544..773a46018 100644 --- a/auth/oidc/lang/en/auth_oidc.php +++ b/auth/oidc/lang/en/auth_oidc.php @@ -401,7 +401,7 @@
{$a}
'; $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 Binding Username Claim setting is set to Custom.'; $string['binding_username_claim_help_ms_no_user_sync'] = 'The options for non Microsoft IdPs include: diff --git a/auth/oidc/version.php b/auth/oidc/version.php index 432712ecf..b51d00996 100644 --- a/auth/oidc/version.php +++ b/auth/oidc/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2023042435; +$plugin->version = 2023042436; $plugin->requires = 2023042400; $plugin->release = '4.2.8'; $plugin->component = 'auth_oidc';