From 675b291d47f9eff3bc1aaa609b6849c42bb8d2f4 Mon Sep 17 00:00:00 2001 From: Sebastian Tabares Amaya Date: Fri, 7 Jul 2017 09:12:11 -0500 Subject: [PATCH] MDL-59473 request: Fix Loop Redirection in Oauth2 --- lib/oauthlib.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/oauthlib.php b/lib/oauthlib.php index 8f3e7957959..f918112f118 100644 --- a/lib/oauthlib.php +++ b/lib/oauthlib.php @@ -557,6 +557,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 (!empty($r->error)) { throw new moodle_exception($r->error . ' ' . $r->error_description); } @@ -610,6 +614,9 @@ abstract class oauth2_client extends curl { } } + // Force JSON format content in response. + $this->setHeader('Accept: application/json'); + $response = parent::request($murl->out(false), $options); $this->resetHeader();