Skip to content

Commit

Permalink
Merge pull request #76 from lmcsu/multiple-token-refresh-fix
Browse files Browse the repository at this point in the history
Обновление токена срабатывает несколько раз
  • Loading branch information
bessudnov authored Jul 16, 2020
2 parents 63ee7c9 + 354de2b commit cd02d7e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/AmoCRM/Client/AmoCRMApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,17 @@ public function onAccessTokenRefresh(callable $callback): self
private function buildRequest(): AmoCRMApiRequest
{
$oAuthClient = $this->getOAuthClient();
if (is_callable($this->accessTokenRefreshCallback)) {
$oAuthClient->setAccessTokenRefreshCallback($this->accessTokenRefreshCallback);
}

$oAuthClient->setAccessTokenRefreshCallback(
function (AccessToken $accessToken, string $baseAccountDomain) use ($oAuthClient) {
$this->setAccessToken($accessToken);

if (is_callable($this->accessTokenRefreshCallback)) {
$callback = $this->accessTokenRefreshCallback;
$callback($accessToken, $baseAccountDomain);
}
}
);

return new AmoCRMApiRequest($this->accessToken, $oAuthClient);
}
Expand Down

0 comments on commit cd02d7e

Please sign in to comment.