Skip to content

Commit

Permalink
Merge pull request #572 from epavlyuchenkov/feature/WALITE-717
Browse files Browse the repository at this point in the history
fix get subdomain in refresh token request
  • Loading branch information
bessudnov authored Sep 5, 2024
2 parents cb3db13 + d1167bc commit 6b06dfc
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/AmoCRM/OAuth/AmoCRMOAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,34 @@ public function getAccessTokenByRefreshToken(AccessTokenInterface $accessToken):
'refresh_token' => $accessToken->getRefreshToken(),
]);
} catch (IdentityProviderException $e) {
throw new AmoCRMoAuthApiException(
$e->getMessage(),
$e->getCode(),
[],
$e->getResponseBody(),
$e
);
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(),
]);
} 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)) {
Expand Down

0 comments on commit 6b06dfc

Please sign in to comment.