MDL-76172 core: Fix error when userinfo is false

This patch should fix a regression introduced in MDL-75171, raised
while running the OBv2.1 certification.
The new method get_raw_userinfo() can return stdClass or false but
the second one was not taken into account from get_userid() (so an
error was thrown: "Argument 1 passed to
core\oauth2\client::map_userinfo_to_fields() must be an instance
of stdClass, bool given").
This commit is contained in:
Sara Arjona 2022-11-02 12:28:15 +01:00
parent 720bd60fc6
commit ae63a2d16b

View file

@ -488,7 +488,7 @@ class client extends \oauth2_client {
/** /**
* Fetch the user info from the user info endpoint. * Fetch the user info from the user info endpoint.
* *
* @return array|false Moodle user fields for the logged in user (or false if request failed) * @return stdClass|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. * @throws moodle_exception if the response is empty after decoding it.
*/ */
public function get_raw_userinfo() { public function get_raw_userinfo() {
@ -528,6 +528,10 @@ class client extends \oauth2_client {
*/ */
public function get_userinfo() { public function get_userinfo() {
$userinfo = $this->get_raw_userinfo(); $userinfo = $this->get_raw_userinfo();
if ($userinfo === false) {
return false;
}
return $this->map_userinfo_to_fields($userinfo); return $this->map_userinfo_to_fields($userinfo);
} }