Skip to content

Commit

Permalink
MDL-59645 oauth1: Improve reporting of token errors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mudrd8mz committed Sep 19, 2017
1 parent f2252e9 commit a650517
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lang/en/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@
$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';
Expand Down
7 changes: 6 additions & 1 deletion lib/oauthlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function request_token() {
// 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'];
Expand Down Expand Up @@ -265,6 +265,11 @@ public function get_access_token($token, $secret, $verifier='') {
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;
}
Expand Down

0 comments on commit a650517

Please sign in to comment.