Merge branch 'MDL-73827-311' of https://github.com/sarjona/moodle into MOODLE_311_STABLE

This commit is contained in:
Jun Pataleta
2022-02-16 16:52:16 +08:00
+10
View File
@@ -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);
}