From eb1f34a7b0b6b8f3eff4d0aea503a69284a24232 Mon Sep 17 00:00:00 2001 From: mesilov Date: Sat, 9 Sep 2023 02:34:53 +0400 Subject: [PATCH] fix errors for Core Signed-off-by: mesilov --- CHANGELOG.md | 3 ++- src/Core/Core.php | 10 ++++++++++ .../Exceptions/AuthForbiddenException.php | 9 +++++++++ tests/Integration/Core/CoreTest.php | 19 +++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/Core/Exceptions/AuthForbiddenException.php diff --git a/CHANGELOG.md b/CHANGELOG.md index a8138f8d..81ff9ad6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,7 +64,8 @@ * fix [add helper metods isError for registerCallResult fortelephony](https://github.com/mesilov/bitrix24-php-sdk/issues/335) * fix [add return type for crm multifields phone, email, im](https://github.com/mesilov/bitrix24-php-sdk/issues/338) * fix errors in `ShowFieldsDescriptionCommand` metadata reader CLI command -* fix errors for `ApplicationProfile` with empty scope +* fix errors for `ApplicationProfile` with empty scope +* fix errors in `Core` with auth attempt to non-exists portal ### etc * move CLI entry point to `bin/console` diff --git a/src/Core/Core.php b/src/Core/Core.php index a739fe9a..73511395 100644 --- a/src/Core/Core.php +++ b/src/Core/Core.php @@ -7,6 +7,7 @@ use Bitrix24\SDK\Core\Commands\Command; use Bitrix24\SDK\Core\Contracts\ApiClientInterface; use Bitrix24\SDK\Core\Contracts\CoreInterface; +use Bitrix24\SDK\Core\Exceptions\AuthForbiddenException; use Bitrix24\SDK\Core\Exceptions\BaseException; use Bitrix24\SDK\Core\Exceptions\TransportException; use Bitrix24\SDK\Core\Response\Response; @@ -146,6 +147,15 @@ public function call(string $apiMethod, array $parameters = []): Response throw new BaseException('UNAUTHORIZED request error'); } break; + case StatusCodeInterface::STATUS_FORBIDDEN: + $this->logger->warning( + 'bitrix24 portal authorisation forbidden', + [ + 'apiMethod' => $apiMethod, + 'b24DomainUrl' => $this->apiClient->getCredentials()->getDomainUrl(), + ] + ); + throw new AuthForbiddenException(sprintf('authorisation forbidden for portal %s ', $this->apiClient->getCredentials()->getDomainUrl())); case StatusCodeInterface::STATUS_SERVICE_UNAVAILABLE: $body = $apiCallResponse->toArray(false); $this->logger->notice( diff --git a/src/Core/Exceptions/AuthForbiddenException.php b/src/Core/Exceptions/AuthForbiddenException.php new file mode 100644 index 00000000..2d444876 --- /dev/null +++ b/src/Core/Exceptions/AuthForbiddenException.php @@ -0,0 +1,9 @@ +assertIsArray($response->getResponseData()->getResult()); } + public function testConnectToNonExistsBitrix24PortalInCloud():void + { + $core = (new CoreBuilder()) + ->withCredentials(Credentials::createFromOAuth( + new AccessToken('non-exists-access-token','refresh-token', 3600), + new ApplicationProfile('non-exists-client-id', 'non-exists-client-secret', new Scope([])), + 'non-exists-domain.bitrix24.com' + )) + ->build(); + $this->expectException(AuthForbiddenException::class); + $core->call('app.info'); + } + /** * @return void * @throws \Bitrix24\SDK\Core\Exceptions\BaseException