Skip to content

Commit

Permalink
handle subdomain change
Browse files Browse the repository at this point in the history
  • Loading branch information
bessudnov committed Sep 5, 2024
1 parent 6b06dfc commit 25a7a19
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/AmoCRM/OAuth/AmoCRMOAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 25a7a19

Please sign in to comment.