Skip to content

Commit

Permalink
Merge pull request #55 from picqer/refresh-token-body
Browse files Browse the repository at this point in the history
Refresh token as body instead of querystring
  • Loading branch information
casperbakker authored Nov 11, 2024
2 parents 6770110 + dff1ad3 commit 9d21020
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
5 changes: 3 additions & 2 deletions src/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,10 @@ protected function requestToken(string $clientId, string $clientSecret, TokenReq
$response = $this->rawRequest('POST', static::API_TOKEN_URI, [
'headers' => [
'Accept' => 'application/json',
'Authorization' => sprintf('Basic %s', $credentials)
'Authorization' => sprintf('Basic %s', $credentials),
'Content-Type' => 'application/x-www-form-urlencoded',
],
'query' => $token->toArray()
'body' => http_build_query($token->toArray())
]);

$responseTypes = [
Expand Down
24 changes: 9 additions & 15 deletions tests/BaseClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,10 @@ protected function authenticateByClientCredentials(?ResponseInterface $response
$httpClientMock->method('request')->with('POST', 'https://login.bol.com/token', [
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Basic ' . $credentials
'Authorization' => 'Basic ' . $credentials,
'Content-Type' => 'application/x-www-form-urlencoded'
],
'query' => [
'grant_type' => 'client_credentials'
]
'body' => 'grant_type=client_credentials'
])->willReturn($response);

// use the HttpClient mock created in this method for authentication, put the original one back afterwards
Expand Down Expand Up @@ -373,13 +372,10 @@ protected function authenticateByAuthorizationCode(?ResponseInterface $response
$httpClientMock->method('request')->with('POST', 'https://login.bol.com/token', [
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Basic ' . $credentials
'Authorization' => 'Basic ' . $credentials,
'Content-Type' => 'application/x-www-form-urlencoded'
],
'query' => [
'grant_type' => 'authorization_code',
'code' => '123456',
'redirect_uri' => 'http://someserver.xxx/redirect',
]
'body' => 'grant_type=authorization_code&code=123456&redirect_uri=http%3A%2F%2Fsomeserver.xxx%2Fredirect'
])->willReturn($response);

// use the HttpClient mock created in this method for authentication, put the original one back afterwards
Expand Down Expand Up @@ -428,12 +424,10 @@ protected function authenticateByRefreshToken(?ResponseInterface $response = nul
$httpClientMock->method('request')->with('POST', 'https://login.bol.com/token', [
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Basic ' . $credentials
'Authorization' => 'Basic ' . $credentials,
'Content-Type' => 'application/x-www-form-urlencoded'
],
'query' => [
'grant_type' => 'refresh_token',
'refresh_token' => $this->validRefreshToken->getToken()
]
'body' => 'grant_type=refresh_token&refresh_token=' . $this->validRefreshToken->getToken()
])->willReturn($response);

// use the HttpClient mock created in this method for authentication, put the original one back afterwards
Expand Down
7 changes: 3 additions & 4 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ protected function authenticateByClientCredentials()
$httpClientMock->method('request')->with('POST', 'https://login.bol.com/token', [
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Basic ' . $credentials
'Authorization' => 'Basic ' . $credentials,
'Content-Type' => 'application/x-www-form-urlencoded'
],
'query' => [
'grant_type' => 'client_credentials'
]
'body' => 'grant_type=client_credentials'
])->willReturn($response);

// use the HttpClient mock created in this method for authentication, put the original one back afterwards
Expand Down

0 comments on commit 9d21020

Please sign in to comment.