Skip to content

Commit

Permalink
Merge pull request #246 from hanneskaeufler/hk-fix-xing-token-parsing
Browse files Browse the repository at this point in the history
xing responds with json encoded errors
  • Loading branch information
David Desberg authored and David Desberg committed Sep 14, 2015
2 parents 26fdd6b + 7d58320 commit 10d450e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/OAuth/OAuth1/Service/Xing.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ protected function parseRequestTokenResponse($responseBody)
protected function parseAccessTokenResponse($responseBody)
{
parse_str($responseBody, $data);
$errors = json_decode($responseBody);

if (null === $data || !is_array($data)) {
throw new TokenResponseException('Unable to parse response.');
} elseif (isset($data['error'])) {
throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
} elseif ($errors) {
throw new TokenResponseException('Error in retrieving token: "' . $errors->error_name . '"');
}

$token = new StdOAuth1Token();
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/OAuth1/Service/XingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public function testParseAccessTokenResponseThrowsExceptionOnError()
$this->client
->expects($this->once())
->method('retrieveResponse')
->will($this->returnValue('error=bar'));
->will($this->returnValue('{"message":"Invalid OAuth signature","error_name":"INVALID_OAUTH_SIGNATURE"}'));

$token = $this->getMock('\\OAuth\\OAuth1\\Token\\TokenInterface');

Expand Down

0 comments on commit 10d450e

Please sign in to comment.