From 33ff698c292e3c04c303522a6c7a307ea9d38629 Mon Sep 17 00:00:00 2001 From: Wim Griffioen Date: Mon, 6 Nov 2023 15:56:30 +0100 Subject: [PATCH] Use the correct URL when refreshing access tokens --- src/Connection.php | 13 +++---------- tests/ConnectionTest.php | 6 +++--- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index 1d92d66..7c1c85b 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -33,9 +33,7 @@ class Connection private const TOKEN_URL = '/oauth/token'; - private const REFRESH_URL = '/oauth/token/refresh'; - - private const VERSION = '1.0'; + private const VERSION = '1.0.1'; /** @var Client|null */ private ?Client $client = null; @@ -289,8 +287,6 @@ private function acquireAccessToken(): void 'client_secret' => $this->clientSecret, 'code' => $this->authorizationCode, ]; - - $response = $this->getClient()->post(self::BASE_URL . self::TOKEN_URL, ['form_params' => $parameters]); } else { $parameters = [ 'refresh_token' => $this->refreshToken, @@ -298,13 +294,10 @@ private function acquireAccessToken(): void 'client_id' => $this->clientId, 'client_secret' => $this->clientSecret, ]; - - $response = $this->getClient()->post( - self::BASE_URL . self::REFRESH_URL, - ['form_params' => $parameters] - ); } + $response = $this->getClient()->post(self::BASE_URL . self::TOKEN_URL, ['form_params' => $parameters]); + Message::rewindBody($response); $responseBody = $response->getBody()->getContents(); diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index d265fb2..1ac7589 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -23,7 +23,7 @@ public function testUserAgentIsSet(): void $connection = new Connection(); $this->assertEquals( - sprintf('Sendy/1.0 PHP/%s', phpversion()), + sprintf('Sendy/1.0.1 PHP/%s', phpversion()), $connection->getClient()->getConfig('headers')['User-Agent'] ); @@ -31,7 +31,7 @@ public function testUserAgentIsSet(): void $connection->setOauthClient(true); $this->assertEquals( - sprintf('Sendy/1.0 PHP/%s OAuth/2.0', phpversion()), + sprintf('Sendy/1.0.1 PHP/%s OAuth/2.0', phpversion()), $connection->getClient()->getConfig('headers')['User-Agent'] ); } @@ -288,7 +288,7 @@ public function testTokensAreAcquiredWithRefreshToken(): void $this->assertEquals(time() + 3600, $connection->getTokenExpires()); $this->assertEquals( - 'https://app.sendy.nl/oauth/token/refresh', + 'https://app.sendy.nl/oauth/token', (string) $mockHandler->getLastRequest()->getUri() ); }