From 23b74cd8cfdb7d62863454ca871af2fd68b8234e Mon Sep 17 00:00:00 2001 From: epavlyuchenkov Date: Mon, 2 Sep 2024 13:20:14 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=BC=D0=B5=D0=BD=D0=B0=20=D1=81=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BC=D0=BE=D1=89=D1=8C=D1=8E=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0=20=D0=B2=20=D1=81?= =?UTF-8?q?=D0=BB=D1=83=D1=87=D0=B0=D0=B5=20=D0=B5=D1=81=D0=BB=D0=B8=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D0=BD=D0=B0=D0=B9=D0=B4=D0=B5=D0=BD=D0=BE=20?= =?UTF-8?q?=D0=B0=D0=BA=D0=BA=D0=B0=D1=83=D0=BD=D1=82=D0=B0=20=D0=BF=D0=BE?= =?UTF-8?q?=20=D1=83=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D0=BE=D0=BC=D1=83=20=D0=B4=D0=BE=D0=BC=D0=B5=D0=BD=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/AmoCRM/OAuth/AmoCRMOAuth.php | 33 +++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/AmoCRM/OAuth/AmoCRMOAuth.php b/src/AmoCRM/OAuth/AmoCRMOAuth.php index 8d704efc..f86eaab7 100755 --- a/src/AmoCRM/OAuth/AmoCRMOAuth.php +++ b/src/AmoCRM/OAuth/AmoCRMOAuth.php @@ -164,13 +164,32 @@ public function getAccessTokenByRefreshToken(AccessTokenInterface $accessToken): 'refresh_token' => $accessToken->getRefreshToken(), ]); } catch (IdentityProviderException $e) { - throw new AmoCRMoAuthApiException( - $e->getMessage(), - $e->getCode(), - [], - $e->getResponseBody(), - $e - ); + if ($e->getCode() === StatusCodeInterface::STATUS_NOT_FOUND) { + $accountDomainModel = $this->getAccountDomainByRefreshToken($accessToken); + $this->setBaseDomain($accountDomainModel->getDomain()); + + try { + $accessToken = $this->oauthProvider->getAccessToken(new RefreshToken(), [ + 'refresh_token' => $accessToken->getRefreshToken(), + ]); + } catch (IdentityProviderException $e) { + throw new AmoCRMoAuthApiException( + $e->getMessage(), + $e->getCode(), + [], + $e->getResponseBody(), + $e + ); + } + } else { + throw new AmoCRMoAuthApiException( + $e->getMessage(), + $e->getCode(), + [], + $e->getResponseBody(), + $e + ); + } } if (is_callable($this->accessTokenRefreshCallback)) { From d1167bcc02fdac90594dbd4838f04a874586a00d Mon Sep 17 00:00:00 2001 From: epavlyuchenkov Date: Tue, 3 Sep 2024 09:58:13 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20=D0=B2=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D1=83=20?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D1=82=D1=83=D1=81=D0=B0=20401=20=D0=BE=D1=82?= =?UTF-8?q?=D0=B2=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/AmoCRM/OAuth/AmoCRMOAuth.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/AmoCRM/OAuth/AmoCRMOAuth.php b/src/AmoCRM/OAuth/AmoCRMOAuth.php index f86eaab7..5aee9b64 100755 --- a/src/AmoCRM/OAuth/AmoCRMOAuth.php +++ b/src/AmoCRM/OAuth/AmoCRMOAuth.php @@ -164,7 +164,9 @@ public function getAccessTokenByRefreshToken(AccessTokenInterface $accessToken): 'refresh_token' => $accessToken->getRefreshToken(), ]); } catch (IdentityProviderException $e) { - if ($e->getCode() === StatusCodeInterface::STATUS_NOT_FOUND) { + if (in_array( + $e->getCode(), [StatusCodeInterface::STATUS_NOT_FOUND, StatusCodeInterface::STATUS_UNAUTHORIZED], true + )) { $accountDomainModel = $this->getAccountDomainByRefreshToken($accessToken); $this->setBaseDomain($accountDomainModel->getDomain());