Skip to content

Commit

Permalink
Merge pull request #25 from flownative/bugfix/throw-better-exception
Browse files Browse the repository at this point in the history
Throw better exception when authentication fails
  • Loading branch information
kdambekalns authored Feb 3, 2022
2 parents 0b62729 + 8e9187b commit 6e2c0c7
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion Classes/Service/CantoClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Flownative\Canto\Domain\Model\AccountAuthorization;
use Flownative\Canto\Domain\Repository\AccountAuthorizationRepository;
use Flownative\Canto\Exception\AuthenticationFailedException;
use Flownative\Canto\Exception\MissingClientSecretException;
use Flownative\OAuth2\Client\Authorization;
use Flownative\OAuth2\Client\OAuthClientException;
use GuzzleHttp\Client;
Expand All @@ -24,11 +25,14 @@
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\ServerRequest;
use GuzzleHttp\Psr7\Uri;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Core\Bootstrap;
use Neos\Flow\Http\Exception as HttpException;
use Neos\Flow\Http\HttpRequestHandlerInterface;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\Exception\StopActionException;
use Neos\Flow\Mvc\Routing\Exception\MissingActionNameException;
use Neos\Flow\Mvc\Routing\UriBuilder;
use Neos\Flow\Security\Context;
use Neos\Media\Domain\Model\AssetSource\SupportsSortingInterface;
Expand Down Expand Up @@ -118,6 +122,13 @@ public function allowClientCredentialsAuthentication(bool $allowed): void
$this->allowClientCredentialsAuthentication = $allowed;
}

/**
* @throws MissingClientSecretException
* @throws HttpException
* @throws MissingActionNameException
* @throws AuthenticationFailedException
* @throws IdentityProviderException
*/
private function authenticate(): void
{
$oAuthClient = new CantoOAuthClient($this->serviceName);
Expand Down Expand Up @@ -151,7 +162,7 @@ private function authenticate(): void
throw new AuthenticationFailedException('Authentication failed: ' . ($result->help ?? 'Unknown cause'), 1630059881);
}
} else {
throw new \RuntimeException('Security context not initialized and client credentials use not allowed', 1631821639);
throw new MissingClientSecretException('Security context not initialized and client credentials use not allowed', 1631821639);
}
}

Expand All @@ -176,7 +187,11 @@ private function redirectToUri(string $uri): void
* @return ResponseInterface
* @throws AuthenticationFailedException
* @throws GuzzleException
* @throws HttpException
* @throws MissingActionNameException
* @throws MissingClientSecretException
* @throws OAuthClientException
* @throws IdentityProviderException
*/
public function getFile(string $assetProxyId): ResponseInterface
{
Expand Down Expand Up @@ -205,6 +220,10 @@ public function updateFile(string $id, array $metadata): ResponseInterface
* @return ResponseInterface
* @throws AuthenticationFailedException
* @throws GuzzleException
* @throws HttpException
* @throws IdentityProviderException
* @throws MissingActionNameException
* @throws MissingClientSecretException
* @throws OAuthClientException
*/
public function search(string $keyword, array $formatTypes, string $customQueryPart = '', int $offset = 0, int $limit = 50, array $orderings = []): ResponseInterface
Expand Down Expand Up @@ -239,6 +258,10 @@ public function search(string $keyword, array $formatTypes, string $customQueryP
* @return array
* @throws AuthenticationFailedException
* @throws GuzzleException
* @throws HttpException
* @throws IdentityProviderException
* @throws MissingActionNameException
* @throws MissingClientSecretException
* @throws OAuthClientException
* @todo perhaps cache the result
*/
Expand All @@ -255,6 +278,10 @@ public function getCustomFields(): array
* @return array
* @throws AuthenticationFailedException
* @throws GuzzleException
* @throws HttpException
* @throws IdentityProviderException
* @throws MissingActionNameException
* @throws MissingClientSecretException
* @throws OAuthClientException
*/
public function user(): array
Expand All @@ -270,6 +297,10 @@ public function user(): array
* @return array
* @throws AuthenticationFailedException
* @throws GuzzleException
* @throws HttpException
* @throws IdentityProviderException
* @throws MissingActionNameException
* @throws MissingClientSecretException
* @throws OAuthClientException
*/
public function tree(): array
Expand All @@ -286,6 +317,10 @@ public function tree(): array
* @return Uri|null
* @throws AuthenticationFailedException
* @throws GuzzleException
* @throws HttpException
* @throws IdentityProviderException
* @throws MissingActionNameException
* @throws MissingClientSecretException
* @throws OAuthClientException
*/
public function directUri(string $assetProxyId): ?Uri
Expand Down Expand Up @@ -357,6 +392,10 @@ private function getAuthenticatedRequest(Authorization $authorization, string $u
* @return Response
* @throws AuthenticationFailedException
* @throws GuzzleException
* @throws HttpException
* @throws IdentityProviderException
* @throws MissingActionNameException
* @throws MissingClientSecretException
* @throws OAuthClientException
*/
public function sendAuthenticatedRequest(string $uriPathAndQuery, string $method = 'GET', array $bodyFields = []): Response
Expand Down

0 comments on commit 6e2c0c7

Please sign in to comment.