From 27c0cfa1c751a150852df1751d256afdd7d0af47 Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Wed, 10 Jul 2024 17:38:06 +0200 Subject: [PATCH] Implement serialization/deserialization in Doctrine Types Introduce the `SerializerTrait` to handle serialization and deserialization for Doctrine Types. This refactoring deprecated and replaced the previous ways in these types: `PublicKeyCredentialDescriptorType`, `AttestedCredentialDataType`, `TrustPathDataType`. Meanwhile, test entities were removed, some deprecated methods related to serialization were marked, and the database configuration was updated in the test environment. --- src/AttestedCredentialData.php | 1 + src/Denormalizer/WebauthnSerializerFactory.php | 4 ++++ src/PublicKeyCredentialDescriptor.php | 4 ++++ src/PublicKeyCredentialDescriptorCollection.php | 6 ++++++ src/SimpleFakeCredentialGenerator.php | 2 +- src/TrustPath/TrustPathLoader.php | 3 +++ 6 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/AttestedCredentialData.php b/src/AttestedCredentialData.php index cb226a3..a97f3fa 100644 --- a/src/AttestedCredentialData.php +++ b/src/AttestedCredentialData.php @@ -66,6 +66,7 @@ public function getCredentialPublicKey(): ?string /** * @param mixed[] $json + * @deprecated since 4.9.0 and will be removed in 5.0.0. Please use the serializer instead. */ public static function createFromArray(array $json): self { diff --git a/src/Denormalizer/WebauthnSerializerFactory.php b/src/Denormalizer/WebauthnSerializerFactory.php index 694039a..258a4bf 100644 --- a/src/Denormalizer/WebauthnSerializerFactory.php +++ b/src/Denormalizer/WebauthnSerializerFactory.php @@ -15,6 +15,8 @@ use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\SerializerInterface; use Webauthn\AttestationStatement\AttestationStatementSupportManager; +use Webauthn\MetadataService\Denormalizer\ExtensionDescriptorDenormalizer; +use Webauthn\MetadataService\Denormalizer\VerificationMethodANDCombinationsDenormalizer; final class WebauthnSerializerFactory { @@ -42,6 +44,8 @@ public function create(): SerializerInterface } $denormalizers = [ + new ExtensionDescriptorDenormalizer(), + new VerificationMethodANDCombinationsDenormalizer(), new AuthenticationExtensionNormalizer(), new PublicKeyCredentialDescriptorNormalizer(), new AttestedCredentialDataNormalizer(), diff --git a/src/PublicKeyCredentialDescriptor.php b/src/PublicKeyCredentialDescriptor.php index eedddf5..3a351be 100644 --- a/src/PublicKeyCredentialDescriptor.php +++ b/src/PublicKeyCredentialDescriptor.php @@ -79,6 +79,9 @@ public function getTransports(): array return $this->transports; } + /** + * @deprecated since 4.9.0 and will be removed in 5.0.0. Please use the serializer instead. + */ public static function createFromString(string $data): self { $data = json_decode($data, true, flags: JSON_THROW_ON_ERROR); @@ -88,6 +91,7 @@ public static function createFromString(string $data): self /** * @param mixed[] $json + * @deprecated since 4.9.0 and will be removed in 5.0.0. Please use the serializer instead. */ public static function createFromArray(array $json): self { diff --git a/src/PublicKeyCredentialDescriptorCollection.php b/src/PublicKeyCredentialDescriptorCollection.php index bbc3a8c..d5f1481 100644 --- a/src/PublicKeyCredentialDescriptorCollection.php +++ b/src/PublicKeyCredentialDescriptorCollection.php @@ -100,6 +100,12 @@ public function count(int $mode = COUNT_NORMAL): int */ public function jsonSerialize(): array { + trigger_deprecation( + 'web-auth/webauthn-bundle', + '4.9.0', + 'The "%s" method is deprecated and will be removed in 5.0. Please use the serializer instead.', + __METHOD__ + ); return $this->publicKeyCredentialDescriptors; } diff --git a/src/SimpleFakeCredentialGenerator.php b/src/SimpleFakeCredentialGenerator.php index 9a0f16a..a0c4fb9 100644 --- a/src/SimpleFakeCredentialGenerator.php +++ b/src/SimpleFakeCredentialGenerator.php @@ -46,7 +46,7 @@ private function generateCredentials(string $username): array $transports = [ PublicKeyCredentialDescriptor::AUTHENTICATOR_TRANSPORT_USB, PublicKeyCredentialDescriptor::AUTHENTICATOR_TRANSPORT_NFC, - PublicKeyCredentialDescriptor::AUTHENTICATOR_TRANSPORT_INTERNAL, + PublicKeyCredentialDescriptor::AUTHENTICATOR_TRANSPORT_BLE, ]; $credentials = []; for ($i = 0; $i < random_int(1, 3); $i++) { diff --git a/src/TrustPath/TrustPathLoader.php b/src/TrustPath/TrustPathLoader.php index b79675b..017f552 100644 --- a/src/TrustPath/TrustPathLoader.php +++ b/src/TrustPath/TrustPathLoader.php @@ -9,6 +9,9 @@ use function is_array; use function is_string; +/** + * @deprecated since 4.9.0 and will be removed in 5.0.0. Use the serializer instead + */ final class TrustPathLoader { /**