diff --git a/auth/oidc/classes/hook/before_login_completed.php b/auth/oidc/classes/hook/before_login_completed.php new file mode 100644 index 000000000..521c5d067 --- /dev/null +++ b/auth/oidc/classes/hook/before_login_completed.php @@ -0,0 +1,39 @@ +. + +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 + ) { + } +} diff --git a/auth/oidc/classes/loginflow/authcode.php b/auth/oidc/classes/loginflow/authcode.php index a5455603b..69384b777 100644 --- a/auth/oidc/classes/loginflow/authcode.php +++ b/auth/oidc/classes/loginflow/authcode.php @@ -37,6 +37,7 @@ use moodle_url; use pix_icon; use stdClass; +use core\di; defined('MOODLE_INTERNAL') || die(); @@ -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 {