From 7d58320ba52e21c0d77aa61cfe34b2b667e66875 Mon Sep 17 00:00:00 2001 From: Hannes Kaeufler Date: Mon, 5 May 2014 17:35:46 +0200 Subject: [PATCH] xing responds with json encoded errors --- src/OAuth/OAuth1/Service/Xing.php | 5 +++-- tests/Unit/OAuth1/Service/XingTest.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/OAuth/OAuth1/Service/Xing.php b/src/OAuth/OAuth1/Service/Xing.php index 03e3357f..e6824db3 100644 --- a/src/OAuth/OAuth1/Service/Xing.php +++ b/src/OAuth/OAuth1/Service/Xing.php @@ -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(); diff --git a/tests/Unit/OAuth1/Service/XingTest.php b/tests/Unit/OAuth1/Service/XingTest.php index d3a5f4ae..4708b7bb 100644 --- a/tests/Unit/OAuth1/Service/XingTest.php +++ b/tests/Unit/OAuth1/Service/XingTest.php @@ -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');