MDL-59645 oauth1: Improve reporting of token errors

Provide a more meaningful error message and debuginfo allowing to
diagnose what is going on. In case of flickr, this is typically thrown
when flickr API responses with their "bad, bad panda" HTML page instead
of the expected reply.
This commit is contained in:
David Mudrák
2017-09-19 14:39:42 +02:00
parent fde6b9ef06
commit 54525dd238
2 changed files with 8 additions and 1 deletions
+2
View File
@@ -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';
+6 -1
View File
@@ -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;
}