chore: make verifyAuthData private

This commit is contained in:
Maël Gangloff
2025-02-27 09:03:22 +01:00
4 changed files with 13 additions and 11 deletions

View File

@@ -17,6 +17,7 @@ use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\Exception\ExceptionInterface;
use Symfony\Component\Serializer\SerializerInterface;
class ConnectorController extends AbstractController
@@ -48,7 +49,7 @@ class ConnectorController extends AbstractController
}
/**
* @throws \Exception
* @throws ExceptionInterface
* @throws \Throwable
*/
#[Route(
@@ -78,12 +79,11 @@ class ConnectorController extends AbstractController
if (null === $provider) {
throw new BadRequestHttpException('Provider not found');
}
$authData = $connector->getAuthData();
if (ConnectorProvider::EPP === $provider) {
$filesystem = new Filesystem();
$directory = sprintf('%s/%s/', EppClientProvider::EPP_CERTIFICATES_PATH, $connector->getId());
$authData = $connector->getAuthData();
unset($authData['file_certificate_pem'], $authData['file_certificate_key']); // Prevent alteration from user
if (isset($authData['certificate_pem'], $authData['certificate_key'])) {
@@ -98,11 +98,9 @@ class ConnectorController extends AbstractController
/** @var AbstractProvider $providerClient */
$providerClient = $this->locator->get($provider->getConnectorProvider());
$authData = $providerClient->verifyAuthData($connector->getAuthData());
$connector->setAuthData($authData);
try {
$providerClient->authenticate($authData);
$connector->setAuthData($providerClient->authenticate($authData));
} catch (\Throwable $exception) {
$filesystem->remove($directory);
throw $exception;
@@ -110,9 +108,7 @@ class ConnectorController extends AbstractController
} else {
/** @var AbstractProvider $providerClient */
$providerClient = $this->locator->get($provider->getConnectorProvider());
$authData = $providerClient->verifyAuthData($connector->getAuthData());
$connector->setAuthData($authData);
$providerClient->authenticate($authData);
$connector->setAuthData($providerClient->authenticate($authData));
}
$this->logger->info('User {username} authentication data with the {provider} provider has been validated.', [

View File

@@ -41,6 +41,7 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\Exception\ExceptionInterface;
use Symfony\Component\Serializer\SerializerInterface;
class WatchListController extends AbstractController
@@ -154,6 +155,7 @@ class WatchListController extends AbstractController
/**
* @throws \Exception
* @throws ExceptionInterface
*/
private function verifyConnector(WatchList $watchList, ?Connector $connector): void
{

View File

@@ -13,6 +13,7 @@ use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Mime\Address;
use Symfony\Component\Notifier\Recipient\Recipient;
use Symfony\Component\Serializer\Exception\ExceptionInterface;
#[AsMessageHandler]
final readonly class ValidateConnectorCredentialsHandler
@@ -27,6 +28,7 @@ final readonly class ValidateConnectorCredentialsHandler
/**
* @throws TransportExceptionInterface
* @throws ExceptionInterface
*/
public function __invoke(ValidateConnectorCredentials $message): void
{

View File

@@ -52,7 +52,7 @@ abstract class AbstractProvider
* @throws HttpException when the user does not accept the necessary conditions
* @throws ExceptionInterface
*/
public function verifyAuthData(array $authData): array
private function verifyAuthData(array $authData): array
{
/** @var DefaultProviderDto $data */
$data = $this->serializer->denormalize($this->verifyLegalAuthData($authData), $this->dtoClass);
@@ -136,10 +136,12 @@ abstract class AbstractProvider
* @throws ExceptionInterface
* @throws \Exception
*/
public function authenticate(array $authData): void
public function authenticate(array $authData): array
{
$this->authData = $this->verifyAuthData($authData);
$this->assertAuthentication();
return $this->authData;
}
abstract protected function getCachedTldList(): CacheItemInterface;