refactor: use Dto class instead of array

This commit is contained in:
Maël Gangloff
2025-03-03 15:29:21 +01:00
parent f0c9b94754
commit 995d931f56
2 changed files with 3 additions and 10 deletions

View File

@@ -14,7 +14,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\Exception\ExceptionInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class ConnectorController extends AbstractController
{
@@ -23,7 +22,6 @@ class ConnectorController extends AbstractController
private readonly LoggerInterface $logger,
#[Autowire(service: 'service_container')]
private readonly ContainerInterface $locator,
private readonly NormalizerInterface $normalizer,
) {
}
@@ -76,11 +74,7 @@ class ConnectorController extends AbstractController
/** @var AbstractProvider $providerClient */
$providerClient = $this->locator->get($provider->getConnectorProvider());
$authData = $this->normalizer->normalize($providerClient->authenticate($connector->getAuthData()), 'json');
if (!is_array($authData)) {
throw new BadRequestHttpException('Authentication data cannot be normalized.');
}
$connector->setAuthData((array) $authData);
$connector->setAuthData($providerClient->authenticate($connector->getAuthData()));
$this->logger->info('User {username} authentication data with the {provider} provider has been validated.', [
'username' => $user->getUserIdentifier(),

View File

@@ -4,7 +4,6 @@ namespace App\Service\Connector;
use App\Dto\Connector\DefaultProviderDto;
use App\Entity\Domain;
use Exception;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
@@ -127,12 +126,12 @@ abstract class AbstractProvider
* @throws ExceptionInterface
* @throws \Exception
*/
public function authenticate(array $authData): DefaultProviderDto
public function authenticate(array $authData): array
{
$this->authData = $this->verifyAuthData($authData);
$this->assertAuthentication();
return $this->authData;
return $authData;
}
abstract protected function getCachedTldList(): CacheItemInterface;