Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -289,22 +287,17 @@ 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,
'grant_type' => 'refresh_token',
'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();
Expand Down
6 changes: 3 additions & 3 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ 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']
);

$connection = new Connection();
$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']
);
}
Expand Down Expand Up @@ -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()
);
}
Expand Down