diff --git a/lib/classes/oauth2/client.php b/lib/classes/oauth2/client.php index bc2cd05a803..08661b9275b 100644 --- a/lib/classes/oauth2/client.php +++ b/lib/classes/oauth2/client.php @@ -487,9 +487,14 @@ class client extends \oauth2_client { * the fields back into moodle fields. * * @return array|false Moodle user fields for the logged in user (or false if request failed) + * @throws moodle_exception if the response is empty after decoding it. */ public function get_userinfo() { $url = $this->get_issuer()->get_endpoint_url('userinfo'); + if (empty($url)) { + return false; + } + $response = $this->get($url); if (!$response) { return false; @@ -501,6 +506,11 @@ class client extends \oauth2_client { return false; } + if (is_null($userinfo)) { + // Throw an exception displaying the original response, because, at this point, $userinfo shouldn't be empty. + throw new moodle_exception($response); + } + return $this->map_userinfo_to_fields($userinfo); }