From 5d06da4e419a6343fe7dcbc20ca55cf79b0c7e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Wed, 28 Feb 2018 14:17:24 +0100 Subject: [PATCH] MDL-60101 auth_oauth2: Don't allow suspended users to SSO in via OAuth2 Without this patch, users could still log in as a suspended account via OAuth2 SSO feature. --- auth/oauth2/classes/auth.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/auth/oauth2/classes/auth.php b/auth/oauth2/classes/auth.php index aa5f70ce93b..3cfaaaf51c7 100644 --- a/auth/oauth2/classes/auth.php +++ b/auth/oauth2/classes/auth.php @@ -403,7 +403,20 @@ class auth extends \auth_plugin_base { if (!empty($linkedlogin) && empty($linkedlogin->get('confirmtoken'))) { $mappeduser = get_complete_user_data('id', $linkedlogin->get('userid')); - if ($mappeduser && $mappeduser->confirmed) { + if ($mappeduser && $mappeduser->suspended) { + $failurereason = AUTH_LOGIN_SUSPENDED; + $event = \core\event\user_login_failed::create([ + 'userid' => $mappeduser->id, + 'other' => [ + 'username' => $userinfo['username'], + 'reason' => $failurereason + ] + ]); + $event->trigger(); + $SESSION->loginerrormsg = get_string('invalidlogin'); + $client->log_out(); + redirect(new moodle_url('/login/index.php')); + } else if ($mappeduser && $mappeduser->confirmed) { $userinfo = (array) $mappeduser; $userwasmapped = true; } else {