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

Handle empty binding username claim configurations #2723

Open
wants to merge 1 commit into
base: MOODLE_404_STABLE
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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('bindingusernameclaim'),
$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
35 changes: 35 additions & 0 deletions auth/oidc/db/install.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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/)
*/

/**
* 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
Loading