Skip to content

Commit

Permalink
Implement serialization/deserialization in Doctrine Types
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Spomky committed Jul 10, 2024
1 parent b591f08 commit 27c0cfa
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/AttestedCredentialData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 4 additions & 0 deletions src/Denormalizer/WebauthnSerializerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -42,6 +44,8 @@ public function create(): SerializerInterface
}

$denormalizers = [
new ExtensionDescriptorDenormalizer(),
new VerificationMethodANDCombinationsDenormalizer(),
new AuthenticationExtensionNormalizer(),
new PublicKeyCredentialDescriptorNormalizer(),
new AttestedCredentialDataNormalizer(),
Expand Down
4 changes: 4 additions & 0 deletions src/PublicKeyCredentialDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
{
Expand Down
6 changes: 6 additions & 0 deletions src/PublicKeyCredentialDescriptorCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/SimpleFakeCredentialGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
3 changes: 3 additions & 0 deletions src/TrustPath/TrustPathLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand Down

0 comments on commit 27c0cfa

Please sign in to comment.