Skip to content

Commit

Permalink
Merge pull request #381 from enflow-nl/accessTokenPayload
Browse files Browse the repository at this point in the history
Move the access token payload builder below the access token lock callback
  • Loading branch information
stephangroen authored Aug 22, 2019
2 parents 0140283 + fe26b8f commit 31d9425
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/Picqer/Financials/Exact/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,33 +451,33 @@ public function getAccessToken()

private function acquireAccessToken()
{
// If refresh token not yet acquired, do token request
if (empty($this->refreshToken)) {
$body = [
'form_params' => [
'redirect_uri' => $this->redirectUrl,
'grant_type' => 'authorization_code',
'client_id' => $this->exactClientId,
'client_secret' => $this->exactClientSecret,
'code' => $this->authorizationCode,
],
];
} else { // else do refresh token request
$body = [
'form_params' => [
'refresh_token' => $this->refreshToken,
'grant_type' => 'refresh_token',
'client_id' => $this->exactClientId,
'client_secret' => $this->exactClientSecret,
],
];
}

try {
if (is_callable($this->acquireAccessTokenLockCallback)) {
call_user_func($this->acquireAccessTokenLockCallback, $this);
}

// If refresh token not yet acquired, do token request
if (empty($this->refreshToken)) {
$body = [
'form_params' => [
'redirect_uri' => $this->redirectUrl,
'grant_type' => 'authorization_code',
'client_id' => $this->exactClientId,
'client_secret' => $this->exactClientSecret,
'code' => $this->authorizationCode,
],
];
} else { // else do refresh token request
$body = [
'form_params' => [
'refresh_token' => $this->refreshToken,
'grant_type' => 'refresh_token',
'client_id' => $this->exactClientId,
'client_secret' => $this->exactClientSecret,
],
];
}

$response = $this->client()->post($this->getTokenUrl(), $body);

Psr7\rewind_body($response);
Expand Down

0 comments on commit 31d9425

Please sign in to comment.