Skip to content

Commit

Permalink
More deprecations removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Nov 17, 2023
1 parent 750ba28 commit b4b2bb2
Show file tree
Hide file tree
Showing 80 changed files with 129 additions and 2,287 deletions.
67 changes: 2 additions & 65 deletions src/symfony/src/Controller/AssertionControllerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,24 @@
use Psr\Log\NullLogger;
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Webauthn\AuthenticatorAssertionResponseValidator;
use Webauthn\Bundle\CredentialOptionsBuilder\ProfileBasedRequestOptionsBuilder;
use Webauthn\Bundle\CredentialOptionsBuilder\PublicKeyCredentialRequestOptionsBuilder;
use Webauthn\Bundle\Repository\PublicKeyCredentialSourceRepositoryInterface;
use Webauthn\Bundle\Repository\PublicKeyCredentialUserEntityRepositoryInterface;
use Webauthn\Bundle\Security\Handler\FailureHandler;
use Webauthn\Bundle\Security\Handler\RequestOptionsHandler;
use Webauthn\Bundle\Security\Handler\SuccessHandler;
use Webauthn\Bundle\Security\Storage\OptionsStorage;
use Webauthn\Bundle\Service\PublicKeyCredentialRequestOptionsFactory;
use Webauthn\MetadataService\CanLogData;
use Webauthn\PublicKeyCredentialLoader;
use Webauthn\PublicKeyCredentialSourceRepository;

final class AssertionControllerFactory implements CanLogData
{
private LoggerInterface $logger;

public function __construct(
private readonly SerializerInterface $serializer,
private readonly ValidatorInterface $validator,
private readonly PublicKeyCredentialRequestOptionsFactory $publicKeyCredentialRequestOptionsFactory,
private readonly null|PublicKeyCredentialLoader $publicKeyCredentialLoader,
private readonly AuthenticatorAssertionResponseValidator $authenticatorAssertionResponseValidator,
private readonly PublicKeyCredentialUserEntityRepositoryInterface $publicKeyCredentialUserEntityRepository,
private readonly PublicKeyCredentialSourceRepository|PublicKeyCredentialSourceRepositoryInterface $publicKeyCredentialSourceRepository
private readonly PublicKeyCredentialSourceRepositoryInterface $publicKeyCredentialSourceRepository
) {
if ($this->publicKeyCredentialLoader !== null) {
trigger_deprecation(
'web-auth/webauthn-bundle',
'4.8.0',
'The argument "$publicKeyCredentialLoader" is deprecated since 4.5.0 and will be removed in 5.0.0. Please set null instead; the serializer will be used instead.'
);
}
$this->logger = new NullLogger();
}

Expand All @@ -51,28 +34,6 @@ public function setLogger(LoggerInterface $logger): void
$this->logger = $logger;
}

/**
* @deprecated since 4.5.0 and will be removed in 5.0.0. Please use createRequestController instead.
* @infection-ignore-all
*/
public function createAssertionRequestController(
string $profile,
OptionsStorage $optionStorage,
RequestOptionsHandler $optionsHandler,
FailureHandler|AuthenticationFailureHandlerInterface $failureHandler
): AssertionRequestController {
$optionsBuilder = new ProfileBasedRequestOptionsBuilder(
$this->serializer,
$this->validator,
$this->publicKeyCredentialUserEntityRepository,
$this->publicKeyCredentialSourceRepository,
$this->publicKeyCredentialRequestOptionsFactory,
$profile,
);

return $this->createRequestController($optionsBuilder, $optionStorage, $optionsHandler, $failureHandler);
}

public function createRequestController(
PublicKeyCredentialRequestOptionsBuilder $optionsBuilder,
OptionsStorage $optionStorage,
Expand All @@ -88,43 +49,19 @@ public function createRequestController(
);
}

/**
* @param string[] $securedRelyingPartyIds
* @deprecated since 4.5.0 and will be removed in 5.0.0. Please use createResponseController instead.
* @infection-ignore-all
*/
public function createAssertionResponseController(
OptionsStorage $optionStorage,
SuccessHandler $successHandler,
FailureHandler|AuthenticationFailureHandlerInterface $failureHandler,
array $securedRelyingPartyIds
): AssertionResponseController {
return $this->createResponseController(
$optionStorage,
$successHandler,
$failureHandler,
$securedRelyingPartyIds
);
}

/**
* @param null|string[] $securedRelyingPartyIds
*/
public function createResponseController(
OptionsStorage $optionStorage,
SuccessHandler $successHandler,
FailureHandler|AuthenticationFailureHandlerInterface $failureHandler,
null|array $securedRelyingPartyIds = null,
null|AuthenticatorAssertionResponseValidator $authenticatorAssertionResponseValidator = null,
): AssertionResponseController {
return new AssertionResponseController(
$this->publicKeyCredentialLoader ?? $this->serializer,
$this->serializer,
$authenticatorAssertionResponseValidator ?? $this->authenticatorAssertionResponseValidator,
$this->logger,
$optionStorage,
$successHandler,
$failureHandler,
$securedRelyingPartyIds,
$this->publicKeyCredentialSourceRepository
);
}
Expand Down
29 changes: 8 additions & 21 deletions src/symfony/src/Controller/AssertionResponseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,29 @@
use Webauthn\Bundle\Security\Storage\OptionsStorage;
use Webauthn\Exception\AuthenticatorResponseVerificationException;
use Webauthn\PublicKeyCredential;
use Webauthn\PublicKeyCredentialLoader;
use Webauthn\PublicKeyCredentialRequestOptions;

final class AssertionResponseController
{
public function __construct(
private readonly SerializerInterface|PublicKeyCredentialLoader $publicKeyCredentialLoader,
private readonly AuthenticatorAssertionResponseValidator $assertionResponseValidator,
private readonly LoggerInterface $logger,
private readonly OptionsStorage $optionsStorage,
private readonly SuccessHandler $successHandler,
private readonly SerializerInterface $serializer,
private readonly AuthenticatorAssertionResponseValidator $assertionResponseValidator,
private readonly LoggerInterface $logger,
private readonly OptionsStorage $optionsStorage,
private readonly SuccessHandler $successHandler,
private readonly FailureHandler|AuthenticationFailureHandlerInterface $failureHandler,
private readonly ?PublicKeyCredentialSourceRepositoryInterface $publicKeyCredentialSourceRepository = null
private readonly ?PublicKeyCredentialSourceRepositoryInterface $publicKeyCredentialSourceRepository = null
) {
if ($this->publicKeyCredentialLoader instanceof PublicKeyCredentialLoader) {
trigger_deprecation(
'web-auth/webauthn-bundle',
'4.8.0',
'The argument "$publicKeyCredentialLoader" is deprecated since 4.8.0 and will be removed in 5.0.0. Please inject a Symfony Serializer instead.'
);
}
}

public function __invoke(Request $request): Response
{
try {
$format = method_exists(
$request,
'getContentTypeFormat'
) ? $request->getContentTypeFormat() : $request->getContentType();
$format = $request->getContentTypeFormat();
$format === 'json' || throw new BadRequestHttpException('Only JSON content type allowed');
$content = $request->getContent();

$publicKeyCredential = $this->publicKeyCredentialLoader instanceof PublicKeyCredentialLoader ? $this->publicKeyCredentialLoader->load(
$content
) : $this->publicKeyCredentialLoader->deserialize($content, PublicKeyCredential::class, 'json');
$publicKeyCredential = $this->serializer->deserialize($content, PublicKeyCredential::class, 'json');
$response = $publicKeyCredential->response;
$response instanceof AuthenticatorAssertionResponse || throw new BadRequestHttpException(
'Invalid response'
Expand Down
63 changes: 2 additions & 61 deletions src/symfony/src/Controller/AttestationControllerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,22 @@

use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Webauthn\AuthenticatorAttestationResponseValidator;
use Webauthn\Bundle\CredentialOptionsBuilder\ProfileBasedCreationOptionsBuilder;
use Webauthn\Bundle\CredentialOptionsBuilder\PublicKeyCredentialCreationOptionsBuilder;
use Webauthn\Bundle\Repository\PublicKeyCredentialSourceRepositoryInterface;
use Webauthn\Bundle\Security\Guesser\UserEntityGuesser;
use Webauthn\Bundle\Security\Handler\CreationOptionsHandler;
use Webauthn\Bundle\Security\Handler\FailureHandler;
use Webauthn\Bundle\Security\Handler\SuccessHandler;
use Webauthn\Bundle\Security\Storage\OptionsStorage;
use Webauthn\Bundle\Service\PublicKeyCredentialCreationOptionsFactory;
use Webauthn\PublicKeyCredentialLoader;
use Webauthn\PublicKeyCredentialSourceRepository;

final class AttestationControllerFactory
{
public function __construct(
private readonly SerializerInterface $serializer,
private readonly ValidatorInterface $validator,
private readonly PublicKeyCredentialCreationOptionsFactory $publicKeyCredentialCreationOptionsFactory,
private readonly null|PublicKeyCredentialLoader $publicKeyCredentialLoader,
private readonly AuthenticatorAttestationResponseValidator $attestationResponseValidator,
private readonly PublicKeyCredentialSourceRepository|PublicKeyCredentialSourceRepositoryInterface $publicKeyCredentialSourceRepository
private readonly PublicKeyCredentialSourceRepositoryInterface $publicKeyCredentialSourceRepository
) {
if ($this->publicKeyCredentialLoader !== null) {
trigger_deprecation(
'web-auth/webauthn-bundle',
'4.8.0',
'The argument "$publicKeyCredentialLoader" is deprecated since 4.5.0 and will be removed in 5.0.0. Please set null instead; the serializer will be used instead.'
);
}
}

/**
* @deprecated since 4.5.0 and will be removed in 5.0.0. Please use createResponseController instead.
* @infection-ignore-all
*/
public function createAttestationRequestController(
UserEntityGuesser $userEntityGuesser,
string $profile,
OptionsStorage $optionStorage,
CreationOptionsHandler $creationOptionsHandler,
FailureHandler|AuthenticationFailureHandlerInterface $failureHandler,
): AttestationRequestController {
$optionsBuilder = new ProfileBasedCreationOptionsBuilder(
$this->serializer,
$this->validator,
$this->publicKeyCredentialSourceRepository,
$this->publicKeyCredentialCreationOptionsFactory,
$profile
);
return $this->createRequestController(
$optionsBuilder,
$userEntityGuesser,
$optionStorage,
$creationOptionsHandler,
$failureHandler
);
}

public function createRequestController(
Expand All @@ -82,36 +40,19 @@ public function createRequestController(
);
}

/**
* @deprecated since 4.5.0 and will be removed in 5.0.0. Please use createResponseController instead.
* @infection-ignore-all
*/
public function createAttestationResponseController(
OptionsStorage $optionStorage,
SuccessHandler $successHandler,
FailureHandler|AuthenticationFailureHandlerInterface $failureHandler
): AttestationResponseController {
return $this->createResponseController($optionStorage, $successHandler, $failureHandler);
}

/**
* @param null|string[] $securedRelyingPartyIds
*/
public function createResponseController(
OptionsStorage $optionStorage,
SuccessHandler $successHandler,
FailureHandler|AuthenticationFailureHandlerInterface $failureHandler,
null|array $securedRelyingPartyIds = null,
null|AuthenticatorAttestationResponseValidator $attestationResponseValidator = null,
): AttestationResponseController {
return new AttestationResponseController(
$this->publicKeyCredentialLoader ?? $this->serializer,
$this->serializer,
$attestationResponseValidator ?? $this->attestationResponseValidator,
$this->publicKeyCredentialSourceRepository,
$optionStorage,
$successHandler,
$failureHandler,
$securedRelyingPartyIds
);
}
}
41 changes: 8 additions & 33 deletions src/symfony/src/Controller/AttestationResponseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,18 @@
use Webauthn\Bundle\Security\Storage\OptionsStorage;
use Webauthn\PublicKeyCredential;
use Webauthn\PublicKeyCredentialCreationOptions;
use Webauthn\PublicKeyCredentialLoader;
use Webauthn\PublicKeyCredentialSourceRepository;
use Webauthn\PublicKeyCredentialUserEntity;

final class AttestationResponseController
{
public function __construct(
private readonly SerializerInterface|PublicKeyCredentialLoader $publicKeyCredentialLoader,
private readonly AuthenticatorAttestationResponseValidator $attestationResponseValidator,
private readonly PublicKeyCredentialSourceRepository|PublicKeyCredentialSourceRepositoryInterface $credentialSourceRepository,
private readonly OptionsStorage $optionStorage,
private readonly SuccessHandler $successHandler,
private readonly FailureHandler|AuthenticationFailureHandlerInterface $failureHandler,
private readonly SerializerInterface $serializer,
private readonly AuthenticatorAttestationResponseValidator $attestationResponseValidator,
private readonly PublicKeyCredentialSourceRepositoryInterface $credentialSourceRepository,
private readonly OptionsStorage $optionStorage,
private readonly SuccessHandler $successHandler,
private readonly FailureHandler|AuthenticationFailureHandlerInterface $failureHandler,
) {
if (! $this->credentialSourceRepository instanceof PublicKeyCredentialSourceRepositoryInterface) {
trigger_deprecation(
'web-auth/webauthn-symfony-bundle',
'4.6.0',
sprintf(
'Since 4.6.0, the parameter "$credentialSourceRepository" expects an instance of "%s". Please implement that interface instead of "%s".',
PublicKeyCredentialSourceRepositoryInterface::class,
PublicKeyCredentialSourceRepository::class
)
);
}
if ($this->publicKeyCredentialLoader instanceof PublicKeyCredentialLoader) {
trigger_deprecation(
'web-auth/webauthn-bundle',
'4.8.0',
'The argument "$publicKeyCredentialLoader" is deprecated since 4.8.0 and will be removed in 5.0.0. Please inject a Symfony Serializer instead.'
);
}
}

public function __invoke(Request $request): Response
Expand All @@ -62,15 +42,10 @@ public function __invoke(Request $request): Response
if (! $this->credentialSourceRepository instanceof CanSaveCredentialSource) {
throw MissingFeatureException::create('Unable to register the credential.');
}
$format = method_exists(
$request,
'getContentTypeFormat'
) ? $request->getContentTypeFormat() : $request->getContentType();
$format = $request->getContentTypeFormat();
$format === 'json' || throw new BadRequestHttpException('Only JSON content type allowed');
$content = $request->getContent();
$publicKeyCredential = $this->publicKeyCredentialLoader instanceof PublicKeyCredentialLoader ? $this->publicKeyCredentialLoader->load(
$content
) : $this->publicKeyCredentialLoader->deserialize($content, PublicKeyCredential::class, 'json');
$publicKeyCredential = $this->serializer->deserialize($content, PublicKeyCredential::class, 'json');
$response = $publicKeyCredential->response;
$response instanceof AuthenticatorAttestationResponse || throw new BadRequestHttpException(
'Invalid response'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Webauthn\AuthenticationExtensions\AuthenticationExtension;
use Webauthn\AuthenticationExtensions\AuthenticationExtensionsClientInputs;
use Webauthn\AuthenticationExtensions\AuthenticationExtensions;
use Webauthn\AuthenticatorSelectionCriteria;
use Webauthn\Bundle\Dto\PublicKeyCredentialCreationOptionsRequest;
use Webauthn\Bundle\Repository\PublicKeyCredentialSourceRepositoryInterface;
use Webauthn\Bundle\Service\PublicKeyCredentialCreationOptionsFactory;
use Webauthn\PublicKeyCredentialCreationOptions;
use Webauthn\PublicKeyCredentialDescriptor;
use Webauthn\PublicKeyCredentialSource;
use Webauthn\PublicKeyCredentialSourceRepository;
use Webauthn\PublicKeyCredentialUserEntity;
use function count;
use function is_array;
Expand All @@ -29,31 +28,17 @@ final class ProfileBasedCreationOptionsBuilder implements PublicKeyCredentialCre
public function __construct(
private readonly SerializerInterface $serializer,
private readonly ValidatorInterface $validator,
private readonly PublicKeyCredentialSourceRepository|PublicKeyCredentialSourceRepositoryInterface $credentialSourceRepository,
private readonly PublicKeyCredentialSourceRepositoryInterface $credentialSourceRepository,
private readonly PublicKeyCredentialCreationOptionsFactory $publicKeyCredentialCreationOptionsFactory,
private readonly string $profile,
) {
if (! $this->credentialSourceRepository instanceof PublicKeyCredentialSourceRepositoryInterface) {
trigger_deprecation(
'web-auth/webauthn-symfony-bundle',
'4.6.0',
sprintf(
'Since 4.6.0, the parameter "$credentialSourceRepository" expects an instance of "%s". Please implement that interface instead of "%s".',
PublicKeyCredentialSourceRepositoryInterface::class,
PublicKeyCredentialSourceRepository::class
)
);
}
}

public function getFromRequest(
Request $request,
PublicKeyCredentialUserEntity $userEntity
): PublicKeyCredentialCreationOptions {
$format = method_exists(
$request,
'getContentTypeFormat'
) ? $request->getContentTypeFormat() : $request->getContentType();
$format = $request->getContentTypeFormat();
$format === 'json' || throw new BadRequestHttpException('Only JSON content type allowed');
$content = $request->getContent();

Expand All @@ -78,7 +63,7 @@ public function getFromRequest(
}
$extensions = null;
if (is_array($optionsRequest->extensions)) {
$extensions = AuthenticationExtensionsClientInputs::create(array_map(
$extensions = AuthenticationExtensions::create(array_map(
static fn (string $name, mixed $data): AuthenticationExtension => AuthenticationExtension::create(
$name,
$data
Expand Down
Loading

0 comments on commit b4b2bb2

Please sign in to comment.