From 900cab236a1d3fe5092e3a0c55275ace96dc403c Mon Sep 17 00:00:00 2001 From: John Ferrraris Date: Sat, 30 May 2015 17:52:26 +0800 Subject: [PATCH 1/5] Fixed double slash in uri base path. Also fixed unit testing related to double slash --- src/Common/Service/AbstractService.php | 2 +- tests/Unit/OAuth2/Service/DeviantArtTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Common/Service/AbstractService.php b/src/Common/Service/AbstractService.php index 1fafd42..4fcfcee 100644 --- a/src/Common/Service/AbstractService.php +++ b/src/Common/Service/AbstractService.php @@ -132,7 +132,7 @@ protected function determineRequestUriFromPath($path) $path = substr($path, 1); } - $uri->setPath($uri->getPath() . '/' . $path); + $uri->setPath(rtrim($uri->getPath(), '/') . '/' . $path); } return $uri; diff --git a/tests/Unit/OAuth2/Service/DeviantArtTest.php b/tests/Unit/OAuth2/Service/DeviantArtTest.php index cce1d7c..d13bf56 100644 --- a/tests/Unit/OAuth2/Service/DeviantArtTest.php +++ b/tests/Unit/OAuth2/Service/DeviantArtTest.php @@ -77,7 +77,7 @@ public function testBaseApiUriIsCorrect() $service->expects($this->once())->method('httpRequest')->willReturnArgument(0); $this->assertEquals( - 'https://www.deviantart.com/api/v1/oauth2//api/method', + 'https://www.deviantart.com/api/v1/oauth2/api/method', (string) $service->request('/api/method') ); } From 23867f6233704bf3b8d355e65fd0ab95556529e4 Mon Sep 17 00:00:00 2001 From: John Ferrraris Date: Wed, 26 Aug 2015 23:40:07 +0800 Subject: [PATCH 2/5] Subtracting 7 seconds on the timestamp for Fitbit service. This will cause an error when the machine is in UTC timezone. --- src/OAuth1/Service/FitBit.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/OAuth1/Service/FitBit.php b/src/OAuth1/Service/FitBit.php index d2ed3bd..72354cd 100644 --- a/src/OAuth1/Service/FitBit.php +++ b/src/OAuth1/Service/FitBit.php @@ -55,4 +55,26 @@ protected function parseAccessTokenResponse($responseBody) return $token; } + /** + * Builds the authorization header array. + * + * @return array + */ + protected function getBasicAuthorizationHeaderInfo() + { + $dateTime = new \DateTime(); + // Substracting 7 seconds since UTC time is somehow 7 seconds + // advance with the maximum allowable timestamp for Fitbit + $timestamp = $dateTime->format('U') - 7; + $headerParameters = [ + 'oauth_callback' => $this->credentials->getCallbackUrl(), + 'oauth_consumer_key' => $this->credentials->getConsumerId(), + 'oauth_nonce' => $this->generateNonce(), + 'oauth_signature_method' => $this->getSignatureMethod(), + 'oauth_timestamp' => $timestamp, + 'oauth_version' => $this->getVersion(), + ]; + + return $headerParameters; + } } From a627a3611f4c80554c555981e5723e833f52682a Mon Sep 17 00:00:00 2001 From: John Ferrraris Date: Thu, 27 Aug 2015 14:02:51 +0800 Subject: [PATCH 3/5] Adjusting the timestamp since execution time is sometimes slow and 7 seconds is not enough of an adjustment. --- src/OAuth1/Service/FitBit.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/OAuth1/Service/FitBit.php b/src/OAuth1/Service/FitBit.php index 72354cd..b1424fb 100644 --- a/src/OAuth1/Service/FitBit.php +++ b/src/OAuth1/Service/FitBit.php @@ -63,9 +63,8 @@ protected function parseAccessTokenResponse($responseBody) protected function getBasicAuthorizationHeaderInfo() { $dateTime = new \DateTime(); - // Substracting 7 seconds since UTC time is somehow 7 seconds - // advance with the maximum allowable timestamp for Fitbit - $timestamp = $dateTime->format('U') - 7; + // Substracting 90 (1min 30s) seconds because sometimes execution is late + $timestamp = $dateTime->format('U') - 90; $headerParameters = [ 'oauth_callback' => $this->credentials->getCallbackUrl(), 'oauth_consumer_key' => $this->credentials->getConsumerId(), From dc196af5e0eb0c2b23289b0f62ffc17fb298d92d Mon Sep 17 00:00:00 2001 From: John Ferrraris Date: Fri, 28 Aug 2015 17:29:38 +0800 Subject: [PATCH 4/5] Adjusting to 3 mins to compensate with the time stamp delay --- src/OAuth1/Service/FitBit.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OAuth1/Service/FitBit.php b/src/OAuth1/Service/FitBit.php index b1424fb..45df991 100644 --- a/src/OAuth1/Service/FitBit.php +++ b/src/OAuth1/Service/FitBit.php @@ -63,8 +63,8 @@ protected function parseAccessTokenResponse($responseBody) protected function getBasicAuthorizationHeaderInfo() { $dateTime = new \DateTime(); - // Substracting 90 (1min 30s) seconds because sometimes execution is late - $timestamp = $dateTime->format('U') - 90; + // Substracting 180 (3mins) seconds because sometimes execution is late + $timestamp = $dateTime->format('U') - 180; $headerParameters = [ 'oauth_callback' => $this->credentials->getCallbackUrl(), 'oauth_consumer_key' => $this->credentials->getConsumerId(), From 2c2e04845a32ef919addc036c0623402136d7466 Mon Sep 17 00:00:00 2001 From: John Ferrraris Date: Tue, 1 Mar 2016 10:44:06 +0800 Subject: [PATCH 5/5] Adjusting timestamp to 5mins and 30 sec --- src/OAuth1/Service/FitBit.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OAuth1/Service/FitBit.php b/src/OAuth1/Service/FitBit.php index 45df991..788f252 100644 --- a/src/OAuth1/Service/FitBit.php +++ b/src/OAuth1/Service/FitBit.php @@ -63,8 +63,8 @@ protected function parseAccessTokenResponse($responseBody) protected function getBasicAuthorizationHeaderInfo() { $dateTime = new \DateTime(); - // Substracting 180 (3mins) seconds because sometimes execution is late - $timestamp = $dateTime->format('U') - 180; + // Substracting 330 (5mins and 30s) seconds because sometimes execution is late + $timestamp = $dateTime->format('U') - 330; $headerParameters = [ 'oauth_callback' => $this->credentials->getCallbackUrl(), 'oauth_consumer_key' => $this->credentials->getConsumerId(),