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

Merge upstream changes into Catalyst maintained branch #11

Open
wants to merge 90 commits into
base: catalyst-41
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
7d2d4ea
Remove "tenantnameorguid" configuration from auth_oidc
weilai-irl Feb 8, 2023
9de4e1d
Don't show notification about provide admin consent again if local_o3…
weilai-irl Feb 27, 2023
f9bfbc0
Merge branch 'wip-89649-m41' into MOODLE_41_STABLE
weilai-irl Feb 27, 2023
bc09b88
Handle error decoding tokens for non-Azure IdP
weilai-irl Feb 27, 2023
c5f2eb3
Merge branch 'wip-89656-m41' into MOODLE_41_STABLE
weilai-irl Feb 27, 2023
a8a302e
Update plugin version for 4.1.1 release
weilai-irl Feb 28, 2023
89e641a
Support UPN change in Azure AD
weilai-irl Jun 7, 2023
9dbfeba
Support syncing "onPremisesSamAccountName" from Azure AD
weilai-irl Jun 13, 2023
acde189
fix(auth_oidc): fallback to sub claim if iod not present
Tchekda Jun 12, 2023
fe7079d
Merge branch 'wip-91839-m401' into MOODLE_401_STABLE
weilai-irl Jun 20, 2023
9217157
Merge branch 'wip-91824-m401' into MOODLE_401_STABLE
weilai-irl Jun 20, 2023
bd0aa04
Update version files for 4.1.2 release
weilai-irl Jun 27, 2023
e0dce20
fix bug in the logic to determine if a connected has Microsoft UPN ch…
weilai-irl Aug 17, 2023
def8c9d
Add settings to control if username auto update is enabled when Micro…
weilai-irl Sep 27, 2023
ecba8a4
fix(auth_oidc): fallback to sub claim if oid not present
Tchekda Jun 12, 2023
a47e5fd
Bug fix in checking whether objectid in token is empty
weilai-irl Sep 27, 2023
83df17d
Add missing configuration item strings
weilai-irl Sep 28, 2023
3a0c18f
Merge branch 'wip-91839-m401' into MOODLE_401_STABLE
weilai-irl Oct 2, 2023
e48a2ef
Merge branch 'wip-94734-m401' into MOODLE_401_STABLE
weilai-irl Oct 2, 2023
135ca15
Update plugin versions for 4.1.3 release
weilai-irl Oct 9, 2023
96616de
Rename Azure AD to Microsoft Entra ID
weilai-irl Nov 10, 2023
ddc2ad0
bug fix in processing email sync from token
weilai-irl Dec 22, 2023
56511ff
Using Client Certificate Path at IdP and authentication
Oct 2, 2023
fa4bbce
fix(auth_oidc): check passphrase existence
Dec 1, 2023
d79730f
Update "File name" certificate source implementation.
weilai-irl Jan 10, 2024
f96aa97
Add styling to certificate private and public key text
weilai-irl Jan 10, 2024
0a0ed8a
Update auth_oidc configuration page validation and redirect rule
weilai-irl Jan 12, 2024
933db90
add function return type declaration
christianabila Jan 16, 2024
6208707
add explicit table affiliation of column 'type'
christianabila Jan 16, 2024
4242dc0
delete local_o365_objects
christianabila Jan 16, 2024
7e3bd32
Fix a bug where UPN change support can't handle uppercase UPN
weilai-irl Jan 23, 2024
2e979b6
Use application token rather than user token to sync photo and timezo…
weilai-irl Jan 24, 2024
d51318c
When determining if a Microsoft UPN is changed, check if the original…
weilai-irl Jan 26, 2024
daaee6c
Debug logging function improvement
weilai-irl Jan 24, 2024
58899f9
clean up exceptions across the plugins
weilai-irl Feb 8, 2024
2c890d1
Add configuration to control secret expiry email recipients
weilai-irl Feb 22, 2024
2dcba94
bug fix in getting email field from token
weilai-irl Feb 22, 2024
5bc5085
Merge branch 'wip-92969-m401' into MOODLE_401_STABLE
weilai-irl Feb 27, 2024
e56967c
Merge branch 'wip-95490-m401' into MOODLE_401_STABLE
weilai-irl Feb 27, 2024
0a5c737
Merge branch 'wip-97576-m401' into MOODLE_401_STABLE
weilai-irl Feb 27, 2024
8f5be79
Merge branch 'wip-97560-m401' into MOODLE_401_STABLE
weilai-irl Feb 27, 2024
dea200f
Merge branch 'wip-97963-m401' into MOODLE_401_STABLE
weilai-irl Feb 27, 2024
dec6d1e
Merge branch 'wip-98015-m401' into MOODLE_401_STABLE
weilai-irl Feb 27, 2024
4e37884
Merge branch 'wip-98023-m401' into MOODLE_401_STABLE
weilai-irl Feb 27, 2024
aaa8c00
Merge branch 'wip-98097-m401' into MOODLE_401_STABLE
weilai-irl Feb 27, 2024
8a90d17
Handle error Graph API calls to get user details and get profile photo
weilai-irl Feb 8, 2024
4df46ba
Merge branch 'wip-98498-m401' into MOODLE_401_STABLE
weilai-irl Feb 27, 2024
c84f7a6
Merge branch 'wip-98511-m401' into MOODLE_401_STABLE
weilai-irl Feb 27, 2024
18e3590
Merge branch 'wip-98201-m401' into MOODLE_401_STABLE
weilai-irl Feb 27, 2024
5b3cded
Merge branch 'wip-98206-m401' into MOODLE_401_STABLE
weilai-irl Feb 27, 2024
376c57e
Fix Entra ID rename missing cases
weilai-irl Feb 27, 2024
68f200b
Merge branch 'wip-97873-m401' into MOODLE_401_STABLE
weilai-irl Feb 27, 2024
1d40bd4
Update auth_oidc configuration page setting availability control
weilai-irl Feb 28, 2024
a76e734
bug fix in connection method constant change
weilai-irl Feb 28, 2024
92622db
bug fix in strpos() function name
weilai-irl Feb 28, 2024
f076c71
Update help text regarding field mapping
weilai-irl Mar 5, 2024
8dd0af3
bug fix in saving configuration changes on manage applications page
weilai-irl Mar 5, 2024
fd21d5b
bug fix on IdP and authentication configuration page UI settings avai…
weilai-irl Mar 7, 2024
fcbe221
Update plugin versions for 4.1.4 release
weilai-irl Mar 8, 2024
3630e20
Implement can_be_manually_set()
OxyOCE Feb 6, 2024
79fea3c
Update plugin versions for 4.1.6 release
weilai-irl Apr 12, 2024
3ca9751
import class auth_oidc\event\action_failed
christianabila Jun 4, 2024
68c9fd1
Silent SSO login implementation
weilai-irl May 13, 2024
146eeb9
Merge branch 'wip-102310-m401' into MOODLE_401_STABLE
weilai-irl Jun 27, 2024
21afa2e
Silent SSO login implementation
weilai-irl May 13, 2024
3df0b99
Merge branch 'wip-100531-m401' into MOODLE_401_STABLE
weilai-irl Jul 1, 2024
2c7938d
Update plugin versions for 4.1.7 release
weilai-irl Jul 1, 2024
6b933b2
Fix invalid link in auth_oidc settings updated notification message
weilai-irl Jul 17, 2024
4078be1
Issue2596 - Fix unit test error
Jul 10, 2024
c74ea69
Fix a bug where clicking OIDC login button doesn't show Microsoft log…
weilai-irl Jul 17, 2024
feac081
Add enhanced OIDC binding ID token claim options
patmr7 Dec 7, 2023
de368d2
Support choosing binding username claim
weilai-irl Dec 18, 2023
7211aff
Check if "bindingusernameclaim" configuration exists
weilai-irl Jan 16, 2024
cec639b
Update binding username claim feature
weilai-irl Mar 7, 2024
9768afa
Performance improvement in getting sample claims from existing token
weilai-irl Apr 8, 2024
46f5781
support update users by email address
weilai-irl Apr 23, 2024
cafec37
Update document about email matching
weilai-irl Apr 23, 2024
f36cd9b
Bug fixes in branch rebase
weilai-irl Jul 19, 2024
89db90f
Create config changes log entries when updating configurations using …
weilai-irl Jul 24, 2024
6369e5b
Bug fixes in branch rebase
weilai-irl Aug 8, 2024
c645620
Remove deprecated event functions
weilai-irl Sep 30, 2024
46285ca
Ensure 'other' attribute of event contains valid JSON content
weilai-irl Sep 30, 2024
6b68d1d
Fix a bug in which user field mapping on login is skipped because of …
weilai-irl Sep 30, 2024
a83a543
Merge branch 'wip-103724-m401' into MOODLE_401_STABLE
weilai-irl Oct 8, 2024
873c410
Merge branch 'wip-103809-m401' into MOODLE_401_STABLE
weilai-irl Oct 8, 2024
4c89b49
Merge branch 'wip-86569-m401' into MOODLE_401_STABLE
weilai-irl Oct 8, 2024
47b0e8b
Merge branch 'wip-103974-m401' into MOODLE_401_STABLE
weilai-irl Oct 8, 2024
1386587
Merge branch 'wip-106816-m401' into MOODLE_401_STABLE
weilai-irl Oct 8, 2024
1acdd4d
Merge branch 'wip-106844-m401' into MOODLE_401_STABLE
weilai-irl Oct 8, 2024
fba24a9
Update plugin versions for 4.1.9 release
weilai-irl Oct 17, 2024
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 README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Microsoft 365 and Azure Active Directory Plugins for Moodle
# Microsoft 365 and Microsoft Entra ID Plugins for Moodle

## OpenID Connect Authentication Plugin.

Expand Down
34 changes: 26 additions & 8 deletions auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class auth_plugin_oidc extends \auth_plugin_base {
* Constructor.
*
* @param null $forceloginflow
* @throws moodle_exception
*/
public function __construct($forceloginflow = null) {
global $SESSION;
Expand All @@ -67,11 +68,20 @@ public function __construct($forceloginflow = null) {
if (class_exists($loginflowclass)) {
$this->loginflow = new $loginflowclass($this->config);
} else {
throw new \coding_exception(get_string('errorbadloginflow', 'auth_oidc'));
throw new moodle_exception('errorbadloginflow', 'auth_oidc');
}
$this->config = $this->loginflow->config;
}

/**
* Returns true if plugin can be manually set.
*
* @return bool
*/
function can_be_manually_set() {
return true;
}

/**
* Returns a list of potential IdPs that this authentication plugin supports. Used to provide links on the login page.
*
Expand Down Expand Up @@ -109,10 +119,10 @@ public function loginpage_hook() {
* Determines if we will redirect to the redirecturi.
*
* @return bool If this returns true then redirect
* @throws \coding_exception
*/
public function should_login_redirect() {
global $SESSION;
global $CFG, $SESSION;

$oidc = optional_param('oidc', null, PARAM_BOOL);
// Also support noredirect param - used by other auth plugins.
$noredirect = optional_param('noredirect', 0, PARAM_BOOL);
Expand All @@ -128,16 +138,23 @@ public function should_login_redirect() {
}

// Check whether we've skipped the login page already.
// This is here because loginpage_hook is called again during form
// submission (all of login.php is processed) and ?oidc=off is not
// preserved forcing us to the IdP.
// This is here because loginpage_hook is called again during form submission (all of login.php is processed) and
// ?oidc=off is not preserved forcing us to the IdP.
//
// This isn't needed when duallogin is on because $oidc will default to 0
// and duallogin is not part of the request.
// This isn't needed when duallogin is on because $oidc will default to 0 and duallogin is not part of the request.
if ((isset($SESSION->oidc) && $SESSION->oidc == 0)) {
return false;
}

// If the user is redirectred to the login page immediately after logging out, don't redirect.
$silentloginmodesetting = get_config('auth_oidc', 'silentloginmode');
$forceredirectsetting = get_config('auth_oidc', 'forceredirect');
$forceloginsetting = get_config('core', 'forcelogin');
if ($silentloginmodesetting && $forceredirectsetting && $forceloginsetting && isset($_SERVER['HTTP_REFERER']) &&
strpos($_SERVER['HTTP_REFERER'], $CFG->wwwroot) !== false) {
return false;
}

// Never redirect if requested so.
if ($oidc === 0) {
$SESSION->oidc = $oidc;
Expand All @@ -147,6 +164,7 @@ public function should_login_redirect() {
if (isset($SESSION->oidc)) {
unset($SESSION->oidc);
}

return true;
}

Expand Down
109 changes: 109 additions & 0 deletions binding_username_claim.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?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/>.

/**
* Manage binding username claim page.
*
* @package auth_oidc
* @author Lai Wei <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright (C) 2023 onwards Microsoft, Inc. (http://microsoft.com/)
*/

use auth_oidc\form\binding_username_claim;

require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->dirroot . '/auth/oidc/lib.php');

require_login();

$url = new moodle_url('/auth/oidc/binding_username_claim.php');
$PAGE->set_url($url);
$PAGE->set_context(context_system::instance());
$PAGE->set_pagelayout('admin');
$PAGE->set_heading(get_string('settings_page_binding_username_claim', 'auth_oidc'));
$PAGE->set_title(get_string('settings_page_binding_username_claim', 'auth_oidc'));

admin_externalpage_setup('auth_oidc_binding_username_claim');

require_admin();

$form = new binding_username_claim(null);
$formdata = [];

// Validate auth_oidc_binding_username_claim settings.
$predefinedbindingclaims = ['auto', 'preferred_username', 'email', 'upn', 'unique_name', 'sub', 'oid', 'samaccountname'];

$oidcconfig = get_config('auth_oidc');
if (!isset($oidcconfig->bindingusernameclaim)) {
// bindingusernameclaim is not set, set default value.
$formdata['bindingusernameclaim'] = 'auto';
$formdata['customclaimname'] = '';
set_config('bindingusernameclaim', 'auto', 'auth_oidc');
} else if(!$oidcconfig->bindingusernameclaim) {
$formdata['bindingusernameclaim'] = 'auto';
$formdata['customclaimname'] = '';
} else if (in_array($oidcconfig->bindingusernameclaim, $predefinedbindingclaims)) {
$formdata['bindingusernameclaim'] = $oidcconfig->bindingusernameclaim;
$formdata['customclaimname'] = '';
} else {
$formdata['bindingusernameclaim'] = 'custom';
$formdata['customclaimname'] = $oidcconfig->bindingusernameclaim;
}

$form->set_data($formdata);

if ($form->is_cancelled()) {
redirect($url);
} else if ($fromform = $form->get_data()) {
$configstosave = ['bindingusernameclaim', 'customclaimname'];

$configchanged = false;

foreach ($configstosave as $config) {
if (isset($fromform->$config)) {
$existingsetting = $oidcconfig->$config;
if ($fromform->$config != $existingsetting) {
$configchanged = true;
set_config($config, $fromform->$config, 'auth_oidc');
add_to_config_log($config, $existingsetting, $fromform->$config, 'auth_oidc');
}
}
}

if ($configchanged) {
redirect($url, get_string('binding_username_claim_updated', 'auth_oidc'));
} else {
redirect($url);
}
}

$existingclaims = auth_oidc_get_existing_claims();

echo $OUTPUT->header();

echo $OUTPUT->heading(get_string('binding_username_claim_heading', 'auth_oidc'));
$bindingusernametoolurl = new moodle_url('/auth/oidc/change_binding_username_claim_tool.php');
echo html_writer::tag('p', get_string('binding_username_claim_description', 'auth_oidc', $bindingusernametoolurl->out()));
if ($existingclaims) {
echo html_writer::tag('p', get_string('binding_username_claim_description_existing_claims', 'auth_oidc',
implode(' / ', $existingclaims)));
}

$form->display();

echo $OUTPUT->footer();
128 changes: 128 additions & 0 deletions change_binding_username_claim_tool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?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/>.

/**
* Change binding username claim tool page.
*
* @package auth_oidc
* @author Lai Wei <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright (C) 2023 onwards Microsoft, Inc. (http://microsoft.com/)
*/

use auth_oidc\form\change_binding_username_claim_tool_form1;
use auth_oidc\form\change_binding_username_claim_tool_form2;
use auth_oidc\preview;
use auth_oidc\process;

require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->libdir . '/csvlib.class.php');

require_login();

$url = new moodle_url('/auth/oidc/change_binding_username_claim_tool.php');
$PAGE->set_url($url);
$PAGE->set_context(context_system::instance());
$PAGE->set_pagelayout('admin');
$PAGE->set_heading(get_string('settings_page_change_binding_username_claim_tool', 'auth_oidc'));
$PAGE->set_title(get_string('settings_page_change_binding_username_claim_tool', 'auth_oidc'));

admin_externalpage_setup('auth_oidc_change_binding_username_claim_tool');

require_admin();

$iid = optional_param('iid', '', PARAM_INT);
$previewrows = optional_param('previewrows', 10, PARAM_INT);

core_php_time_limit::raise(60 * 60); // 1 hour should be enough.
raise_memory_limit(MEMORY_HUGE);

if (empty($iid)) {
$form1 = new change_binding_username_claim_tool_form1();
if ($formdata = $form1->get_data()) {
$iid = csv_import_reader::get_new_iid('changebindingusernameclaimtool');
$cir = new csv_import_reader($iid, 'changebindingusernameclaimtool');

$content = $form1->get_file_content('usernamefile');

$readcount = $cir->load_csv_content($content, $formdata->encoding, $formdata->delimiter_name);
$csvloaderror = $cir->get_error();
unset($content);

if (!is_null($csvloaderror)) {
throw new moodle_exception('csvloaderror', '', $url, $csvloaderror);
}
} else {
echo $OUTPUT->header();

echo $OUTPUT->heading(get_string('change_binding_username_claim_tool', 'auth_oidc'));
$bindingusernameclaimurl = new moodle_url('/auth/oidc/binding_username_claim.php');
echo html_writer::tag('p', get_string('change_binding_username_claim_tool_description', 'auth_oidc',
$bindingusernameclaimurl->out()));

$form1->display();

echo $OUTPUT->footer();
exit;
}
} else {
$cir = new csv_import_reader($iid, 'changebindingusernameclaimtool');
}

// Test if columns ok.
$process = new process($cir);
$filecolumns = $process->get_file_columns();

$mform2 = new change_binding_username_claim_tool_form2(null,
['columns' => $filecolumns, 'data' => ['iid' => $iid, 'previewrows' => $previewrows]]);

// If a file has been uploaded, then process it.
if ($mform2->is_cancelled()) {
$cir->cleanup(true);
redirect($url);
} else if ($formdata = $mform2->get_data()) {
// Print the header.
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('change_binding_username_claim_tool_result', 'auth_oidc'));

$process->set_form_data($formdata);
$process->process();

echo $OUTPUT->box_start('boxwidthnarrow boxaligncenter generalbox', 'uploadresults');
echo html_writer::tag('p', join('<br />', $process->get_stats()));
echo $OUTPUT->box_end();

echo $OUTPUT->footer();
exit;
}

// Print the header.
echo $OUTPUT->header();

echo $OUTPUT->heading(get_string('change_binding_username_claim_tool', 'auth_oidc'));

$table = new preview($cir, $filecolumns, $previewrows);

echo html_writer::tag('div', html_writer::table($table), ['class' => 'flexible-wrap']);

if ($table->get_no_error()) {
$mform2->display();
}

echo $OUTPUT->footer();

exit;
9 changes: 0 additions & 9 deletions classes/event/action_failed.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,6 @@ public function get_description() {
return $this->data['other'];
}

/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
return array(SITEID, 'auth_oidc', 'error', 'index.php');
}

/**
* Init method.
*
Expand Down
Loading