diff --git a/lang/en/error.php b/lang/en/error.php index cdfa6b71905..55786b47df4 100644 --- a/lang/en/error.php +++ b/lang/en/error.php @@ -448,6 +448,8 @@ $string['notlocalisederrormessage'] = '{$a}'; $string['notmemberofgroup'] = 'You are not a member of this course group'; $string['notownerofkey'] = 'You are not owner of this key'; $string['nousers'] = 'No such user!'; +$string['oauth1accesstoken'] = 'OAuth 1.0 error: We did not obtain the access token.'; +$string['oauth1requesttoken'] = 'OAuth 1.0 error: We did not obtain the request token - the service provider may be temporarily down.'; $string['onlyadmins'] = 'Only administrators can do that'; $string['onlyeditingteachers'] = 'Only editing teachers can do that'; $string['onlyeditown'] = 'You can only edit your own information'; diff --git a/lib/oauthlib.php b/lib/oauthlib.php index f80ad912a87..ff2f68951de 100644 --- a/lib/oauthlib.php +++ b/lib/oauthlib.php @@ -232,7 +232,7 @@ class oauth_helper { // oauth_token_secret $result = $this->parse_result($content); if (empty($result['oauth_token'])) { - throw new moodle_exception('Error while requesting an oauth token'); + throw new moodle_exception('oauth1requesttoken', 'core_error', '', null, $content); } // Build oauth authorize url. $result['authorize_url'] = $this->authorize_url . '?oauth_token='.$result['oauth_token']; @@ -265,6 +265,11 @@ class oauth_helper { unset($params['oauth_callback']); $content = $this->http->post($this->access_token_api, $params, $this->http_options); $keys = $this->parse_result($content); + + if (empty($keys['oauth_token']) || empty($keys['oauth_token_secret'])) { + throw new moodle_exception('oauth1accesstoken', 'core_error', '', null, $content); + } + $this->set_access_token($keys['oauth_token'], $keys['oauth_token_secret']); return $keys; }