Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
WebAuthnSerializerFactory
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 2
6
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 create
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * cf https://github.com/web-auth/webauthn-lib/blob/5.2.3/src/Denormalizer/WebauthnSerializerFactory.php
5 *
6 * Changes:
7 * * Re-namespaced and capitalisation of class name changed
8 * * Updated to MW code style
9 * * class_exists() check removed; composer makes sure classes exist
10 * * Mapping of class => package removed, along with related constants
11 * * PhpDocExtractor removed from ObjectNormalizer/PropertyInfoExtractor
12 *
13 * @license MIT
14 */
15
16declare( strict_types = 1 );
17
18namespace MediaWiki\Extension\OATHAuth;
19
20use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
21use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
22use Symfony\Component\Serializer\Encoder\JsonEncoder;
23use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
24use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
25use Symfony\Component\Serializer\Normalizer\UidNormalizer;
26use Symfony\Component\Serializer\Serializer;
27use Symfony\Component\Serializer\SerializerInterface;
28use Webauthn\AttestationStatement\AttestationStatementSupportManager;
29use Webauthn\Denormalizer\AttestationObjectDenormalizer;
30use Webauthn\Denormalizer\AttestationStatementDenormalizer;
31use Webauthn\Denormalizer\AttestedCredentialDataNormalizer;
32use Webauthn\Denormalizer\AuthenticationExtensionNormalizer;
33use Webauthn\Denormalizer\AuthenticationExtensionsDenormalizer;
34use Webauthn\Denormalizer\AuthenticatorAssertionResponseDenormalizer;
35use Webauthn\Denormalizer\AuthenticatorAttestationResponseDenormalizer;
36use Webauthn\Denormalizer\AuthenticatorDataDenormalizer;
37use Webauthn\Denormalizer\AuthenticatorResponseDenormalizer;
38use Webauthn\Denormalizer\CollectedClientDataDenormalizer;
39use Webauthn\Denormalizer\ExtensionDescriptorDenormalizer;
40use Webauthn\Denormalizer\PublicKeyCredentialDenormalizer;
41use Webauthn\Denormalizer\PublicKeyCredentialDescriptorNormalizer;
42use Webauthn\Denormalizer\PublicKeyCredentialOptionsDenormalizer;
43use Webauthn\Denormalizer\PublicKeyCredentialSourceDenormalizer;
44use Webauthn\Denormalizer\PublicKeyCredentialUserEntityDenormalizer;
45use Webauthn\Denormalizer\TrustPathDenormalizer;
46use Webauthn\Denormalizer\VerificationMethodANDCombinationsDenormalizer;
47
48final readonly class WebAuthnSerializerFactory {
49    public function __construct(
50        private AttestationStatementSupportManager $attestationStatementSupportManager
51    ) {
52    }
53
54    public function create(): SerializerInterface {
55        $denormalizers = [
56            new ExtensionDescriptorDenormalizer(),
57            new VerificationMethodANDCombinationsDenormalizer(),
58            new AuthenticationExtensionNormalizer(),
59            new PublicKeyCredentialDescriptorNormalizer(),
60            new AttestedCredentialDataNormalizer(),
61            new AttestationObjectDenormalizer(),
62            new AttestationStatementDenormalizer( $this->attestationStatementSupportManager ),
63            new AuthenticationExtensionsDenormalizer(),
64            new AuthenticatorAssertionResponseDenormalizer(),
65            new AuthenticatorAttestationResponseDenormalizer(),
66            new AuthenticatorDataDenormalizer(),
67            new AuthenticatorResponseDenormalizer(),
68            new CollectedClientDataDenormalizer(),
69            new PublicKeyCredentialDenormalizer(),
70            new PublicKeyCredentialOptionsDenormalizer(),
71            new PublicKeyCredentialSourceDenormalizer(),
72            new PublicKeyCredentialUserEntityDenormalizer(),
73            new TrustPathDenormalizer(),
74            new UidNormalizer(),
75            new ArrayDenormalizer(),
76            new ObjectNormalizer(
77                propertyTypeExtractor: new PropertyInfoExtractor( typeExtractors: [
78                    new ReflectionExtractor(),
79                ] )
80            ),
81        ];
82
83        return new Serializer( $denormalizers, [ new JsonEncoder() ] );
84    }
85}