From 25a7a1960cebc770ed04d5cc07d5c6bf57dd57a8 Mon Sep 17 00:00:00 2001 From: Nikita Date: Thu, 5 Sep 2024 15:14:26 -0300 Subject: [PATCH] handle subdomain change --- src/AmoCRM/OAuth/AmoCRMOAuth.php | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/AmoCRM/OAuth/AmoCRMOAuth.php b/src/AmoCRM/OAuth/AmoCRMOAuth.php index 5aee9b6..53c3319 100755 --- a/src/AmoCRM/OAuth/AmoCRMOAuth.php +++ b/src/AmoCRM/OAuth/AmoCRMOAuth.php @@ -40,8 +40,8 @@ use League\OAuth2\Client\Provider\ResourceOwnerInterface; use League\OAuth2\Client\Token\AccessToken; use League\OAuth2\Client\Token\AccessTokenInterface; - use Throwable; + use function sprintf; /** @@ -164,16 +164,26 @@ public function getAccessTokenByRefreshToken(AccessTokenInterface $accessToken): 'refresh_token' => $accessToken->getRefreshToken(), ]); } catch (IdentityProviderException $e) { - if (in_array( - $e->getCode(), [StatusCodeInterface::STATUS_NOT_FOUND, StatusCodeInterface::STATUS_UNAUTHORIZED], true - )) { + if ( + in_array( + $e->getCode(), + [ + StatusCodeInterface::STATUS_NOT_FOUND, + StatusCodeInterface::STATUS_UNAUTHORIZED, + ], + true + ) + ) { $accountDomainModel = $this->getAccountDomainByRefreshToken($accessToken); $this->setBaseDomain($accountDomainModel->getDomain()); try { - $accessToken = $this->oauthProvider->getAccessToken(new RefreshToken(), [ - 'refresh_token' => $accessToken->getRefreshToken(), - ]); + $accessToken = $this->oauthProvider->getAccessToken( + new RefreshToken(), + [ + 'refresh_token' => $accessToken->getRefreshToken(), + ] + ); } catch (IdentityProviderException $e) { throw new AmoCRMoAuthApiException( $e->getMessage(),