Debian Codegraph @

lib/3rdParty/composer/web-auth/webauthn-lib/src/PublicKeyCredentialCreationOptions.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Webauthn;
6
7 use function in_array;
8 use InvalidArgumentException;
9 use Webauthn\AuthenticationExtensions\AuthenticationExtensions;
10 use Webauthn\Exception\InvalidDataException;
11
12 final class PublicKeyCredentialCreationOptions extends PublicKeyCredentialOptions
13 {
14 public const ATTESTATION_CONVEYANCE_PREFERENCE_DEFAULT = null;
15
16 public const ATTESTATION_CONVEYANCE_PREFERENCE_NONE = 'none';
17
18 public const ATTESTATION_CONVEYANCE_PREFERENCE_INDIRECT = 'indirect';
19
20 public const ATTESTATION_CONVEYANCE_PREFERENCE_DIRECT = 'direct';
21
22 public const ATTESTATION_CONVEYANCE_PREFERENCE_ENTERPRISE = 'enterprise';
23
24 public const ATTESTATION_CONVEYANCE_PREFERENCES = [
25 self::ATTESTATION_CONVEYANCE_PREFERENCE_DEFAULT,
26 self::ATTESTATION_CONVEYANCE_PREFERENCE_NONE,
27 self::ATTESTATION_CONVEYANCE_PREFERENCE_INDIRECT,
28 self::ATTESTATION_CONVEYANCE_PREFERENCE_DIRECT,
29 self::ATTESTATION_CONVEYANCE_PREFERENCE_ENTERPRISE,
30 ];
31
32 public const MEDIATION_DEFAULT = 'default';
33
34 public const MEDIATION_CONDITIONAL = 'conditional';
35
36 public const MEDIATIONS = [self::MEDIATION_DEFAULT, self::MEDIATION_CONDITIONAL];
37
38 /**
39 * Server-side mediation hint. Mirrors the JS `mediation` option of `navigator.credentials.create()`
40 * but is *not* sent to the browser — it controls how the framework validates the response.
41 *
42 * - `MEDIATION_DEFAULT` (default) — full ceremony validation, including User Presence (UP) bit.
43 * - `MEDIATION_CONDITIONAL` — auto-register flow (e.g. SimpleWebAuthn `useAutoRegister: true`):
44 * the UP bit is allowed to be false because the user already authenticated through another
45 * factor (typically password). All other checks remain.
46 *
47 * @see https://github.com/w3c/webauthn/wiki/Explainer:-Conditional-Create
48 */
49 public null|string $mediation = null;
50
51 /**
52 * @param PublicKeyCredentialParameters[] $pubKeyCredParams
53 * @param PublicKeyCredentialDescriptor[] $excludeCredentials
54 * @param null|positive-int $timeout
55 * @param string[] $hints
56 */
57 public function __construct(
58 public readonly PublicKeyCredentialRpEntity $rp,
59 public readonly PublicKeyCredentialUserEntity $user,
60 string $challenge,
61 public array $pubKeyCredParams = [],
62 public null|AuthenticatorSelectionCriteria $authenticatorSelection = null,
63 public null|string $attestation = null,
64 public array $excludeCredentials = [],
65 null|int $timeout = null,
66 null|AuthenticationExtensions $extensions = null,
67 array $hints = [],
68 null|string $mediation = null,
69 ) {
70 foreach ($pubKeyCredParams as $pubKeyCredParam) {
71 $pubKeyCredParam instanceof PublicKeyCredentialParameters || throw new InvalidArgumentException(
72 'Invalid type for $pubKeyCredParams'
73 );
74 }
75 foreach ($excludeCredentials as $excludeCredential) {
76 $excludeCredential instanceof PublicKeyCredentialDescriptor || throw new InvalidArgumentException(
77 'Invalid type for $excludeCredentials'
78 );
79 }
80 in_array($attestation, self::ATTESTATION_CONVEYANCE_PREFERENCES, true) || throw InvalidDataException::create(
81 $attestation,
82 'Invalid attestation conveyance mode'
83 );
84 $mediation === null || in_array($mediation, self::MEDIATIONS, true) || throw InvalidDataException::create(
85 $mediation,
86 'Invalid mediation requirement'
87 );
88
89 $this->mediation = $mediation;
90
91 parent::__construct($challenge, $timeout, $extensions, $hints);
92 }
93
94 /**
95 * @param PublicKeyCredentialParameters[] $pubKeyCredParams
96 * @param PublicKeyCredentialDescriptor[] $excludeCredentials
97 * @param null|positive-int $timeout
98 * @param string[] $hints
99 */
100 public static function create(
101 PublicKeyCredentialRpEntity $rp,
102 PublicKeyCredentialUserEntity $user,
103 string $challenge,
104 array $pubKeyCredParams = [],
105 null|AuthenticatorSelectionCriteria $authenticatorSelection = null,
106 null|string $attestation = null,
107 array $excludeCredentials = [],
108 null|int $timeout = null,
109 null|AuthenticationExtensions $extensions = null,
110 array $hints = [],
111 null|string $mediation = null,
112 ): self {
113 return new self(
114 $rp,
115 $user,
116 $challenge,
117 $pubKeyCredParams,
118 $authenticatorSelection,
119 $attestation,
120 $excludeCredentials,
121 $timeout,
122 $extensions,
123 $hints,
124 $mediation,
125 );
126 }
127 }