MDL-73827 lib: Fix URL blocked error for userinfo endpoint
When the oAuth2 issuer hasn't any userinfo endpoint, a call to $this->get(false) was done, which was returning "The URL is blocked". This is a regression from MDL-70649, which added some cURL security checks.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user