Skip to content
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
39 changes: 39 additions & 0 deletions auth/oidc/classes/hook/before_login_completed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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/>.

namespace auth_oidc\hook;

use auth_oidc\jwt;

/**
* Allow plugins to callback as soon possible after user has completed login.
*
* @package auth_oidc
* @copyright 2026 Ariadne
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
#[\core\attribute\label('Allow plugins to callback as soon possible after user has completed login.')]
#[\core\attribute\tags('user', 'login')]
class before_login_completed {
/**
* Constructor for the hook.
*/
public function __construct(
/** @var jwt The course instance */
public readonly jwt $idtoken
) {
}
}
5 changes: 5 additions & 0 deletions auth/oidc/classes/loginflow/authcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use moodle_url;
use pix_icon;
use stdClass;
use core\di;

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

Expand Down Expand Up @@ -660,6 +661,10 @@ protected function handlelogin(string $oidcuniqid, array $authparams, array $tok
$this->updatetoken($tokenrec->id, $authparams, $tokenparams);
$user = authenticate_user_login($username, '', true);

// Look for plugins that want to add extra checks before user login is completed.
$hook = new \auth_oidc\hook\before_login_completed($idtoken);
di::get(\core\hook\manager::class)->dispatch($hook);

if (!empty($user)) {
complete_user_login($user);
} else {
Expand Down