diff --git a/lib/oauthlib.php b/lib/oauthlib.php index b84c882e795..318f13a602d 100644 --- a/lib/oauthlib.php +++ b/lib/oauthlib.php @@ -510,6 +510,10 @@ abstract class oauth2_client extends curl { $r = json_decode($response); + if (is_null($r)) { + throw new moodle_exception("Could not decode JSON token response"); + } + if (!isset($r->access_token)) { return false; } @@ -552,6 +556,9 @@ abstract class oauth2_client extends curl { } } + // Force JSON format content in response. + $this->setHeader('Accept: application/json'); + return parent::request($murl->out(false), $options); }