From 354de2b0e2e9580e5f896f00192c8007b02ea1e7 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 14 Jul 2020 16:09:50 +0300 Subject: [PATCH] multiple token refresh fix --- src/AmoCRM/Client/AmoCRMApiClient.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/AmoCRM/Client/AmoCRMApiClient.php b/src/AmoCRM/Client/AmoCRMApiClient.php index 6fc177de..c5124626 100644 --- a/src/AmoCRM/Client/AmoCRMApiClient.php +++ b/src/AmoCRM/Client/AmoCRMApiClient.php @@ -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); }