@@ -9,69 +9,132 @@ namespace Microsoft.AspNetCore.Identity;
99public class PasskeyOptions
1010{
1111 /// <summary>
12- /// Gets or sets the time that the server is willing to wait for a passkey operation to complete .
12+ /// Gets or sets the time that the browser should wait for the authenticator to provide a passkey .
1313 /// </summary>
1414 /// <remarks>
15+ /// <para>
16+ /// This option applies to both creating a new passkey and requesting an existing passkey.
17+ /// This is treated as a hint to the browser, and the browser may choose to ignore it.
18+ /// </para>
19+ /// <para>
1520 /// The default value is 5 minutes.
21+ /// </para>
22+ /// <para>
1623 /// See <see href="https://www.w3.org/TR/webauthn-3/#dom-publickeycredentialcreationoptions-timeout"/>
1724 /// and <see href="https://www.w3.org/TR/webauthn-3/#dom-publickeycredentialrequestoptions-timeout"/>.
25+ /// </para>
1826 /// </remarks>
19- public TimeSpan Timeout { get ; set ; } = TimeSpan . FromMinutes ( 5 ) ;
27+ public TimeSpan AuthenticatorTimeout { get ; set ; } = TimeSpan . FromMinutes ( 5 ) ;
2028
2129 /// <summary>
22- /// The size of the challenge in bytes sent to the client during WebAuthn attestation and assertion.
30+ /// Gets or sets the size of the challenge in bytes sent to the client during attestation and assertion.
2331 /// </summary>
2432 /// <remarks>
33+ /// <para>
34+ /// This option applies to both creating a new passkey and requesting an existing passkey.
35+ /// </para>
36+ /// <para>
2537 /// The default value is 32 bytes.
38+ /// </para>
39+ /// <para>
2640 /// See <see href="https://www.w3.org/TR/webauthn-3/#dom-publickeycredentialcreationoptions-challenge"/>
2741 /// and <see href="https://www.w3.org/TR/webauthn-3/#dom-publickeycredentialrequestoptions-challenge"/>.
42+ /// </para>
2843 /// </remarks>
2944 public int ChallengeSize { get ; set ; } = 32 ;
3045
3146 /// <summary>
32- /// The effective domain of the server. Should be unique and will be used as the identity for the server.
47+ /// Gets or sets the effective domain of the server.
48+ /// This should be unique and will be used as the identity for the server.
3349 /// </summary>
3450 /// <remarks>
51+ /// <para>
52+ /// This option applies to both creating a new passkey and requesting an existing passkey.
53+ /// </para>
54+ /// <para>
3555 /// If left <see langword="null"/>, the server's origin may be used instead.
56+ /// </para>
57+ /// <para>
3658 /// See <see href="https://www.w3.org/TR/webauthn-3/#rp-id"/>.
59+ /// </para>
3760 /// </remarks>
3861 public string ? ServerDomain { get ; set ; }
3962
4063 /// <summary>
4164 /// Gets or sets the user verification requirement.
4265 /// </summary>
4366 /// <remarks>
44- /// See <see href="https://www.w3.org/TR/webauthn-3/#enumdef-userverificationrequirement"/>.
67+ /// <para>
68+ /// This option applies to both creating a new passkey and requesting an existing passkey.
69+ /// </para>
70+ /// <para>
4571 /// Possible values are "required", "preferred", and "discouraged".
72+ /// </para>
73+ /// <para>
4674 /// If left <see langword="null"/>, the browser defaults to "preferred".
75+ /// </para>
76+ /// <para>
77+ /// See <see href="https://www.w3.org/TR/webauthn-3/#enumdef-userverificationrequirement"/>.
78+ /// </para>
4779 /// </remarks>
4880 public string ? UserVerificationRequirement { get ; set ; }
4981
5082 /// <summary>
5183 /// Gets or sets the extent to which the server desires to create a client-side discoverable credential.
5284 /// </summary>
5385 /// <remarks>
54- /// See <see href="https://www.w3.org/TR/webauthn-3/#enumdef-residentkeyrequirement"/>.
86+ /// <para>
87+ /// This option only applies when creating a new passkey, and is not enforced on the server.
88+ /// </para>
89+ /// <para>
5590 /// Possible values are "discouraged", "preferred", or "required".
91+ /// </para>
92+ /// <para>
5693 /// If left <see langword="null"/>, the browser defaults to "preferred".
94+ /// </para>
95+ /// <para>
96+ /// See <see href="https://www.w3.org/TR/webauthn-3/#enumdef-residentkeyrequirement"/>.
97+ /// </para>
5798 /// </remarks>
5899 public string ? ResidentKeyRequirement { get ; set ; }
59100
60101 /// <summary>
61102 /// Gets or sets the attestation conveyance preference.
62103 /// </summary>
63104 /// <remarks>
64- /// See <see href="https://www.w3.org/TR/webauthn-3/#enumdef-attestationconveyancepreference"/>.
105+ /// <para>
106+ /// This option only applies when creating a new passkey, and already-registered passkeys are not affected by it.
107+ /// To validate the attestation statement of a passkey during passkey creation, provide a value for the
108+ /// <see cref="VerifyAttestationStatement"/> option.
109+ /// </para>
110+ /// <para>
111+ /// Possible values are "none", "indirect", "direct", and "enterprise".
112+ /// </para>
113+ /// <para>
65114 /// If left <see langword="null"/>, the browser defaults to "none".
115+ /// </para>
116+ /// <para>
117+ /// See <see href="https://www.w3.org/TR/webauthn-3/#enumdef-attestationconveyancepreference"/>.
118+ /// </para>
66119 /// </remarks>
67120 public string ? AttestationConveyancePreference { get ; set ; }
68121
69122 /// <summary>
70- /// Gets or sets the authenticator attachment.
123+ /// Gets or sets the allowed authenticator attachment.
71124 /// </summary>
72125 /// <remarks>
73- /// See <see href="https://www.w3.org/TR/webauthn-3/#enumdef-authenticatorattachment"/>.
126+ /// <para>
127+ /// This option only applies when creating a new passkey, and already-registered passkeys are not affected by it.
128+ /// </para>
129+ /// <para>
130+ /// Possible values are "platform" and "cross-platform".
131+ /// </para>
132+ /// <para>
74133 /// If left <see langword="null"/>, any authenticator attachment modality is allowed.
134+ /// </para>
135+ /// <para>
136+ /// See <see href="https://www.w3.org/TR/webauthn-3/#enumdef-authenticatorattachment"/>.
137+ /// </para>
75138 /// </remarks>
76139 public string ? AuthenticatorAttachment { get ; set ; }
77140
@@ -80,47 +143,42 @@ public class PasskeyOptions
80143 /// is allowed for passkey operations.
81144 /// </summary>
82145 /// <remarks>
83- /// If <see langword="null"/> all supported algorithms are allowed.
146+ /// <para>
147+ /// This option only applies when creating a new passkey, and already-registered passkeys are not affected by it.
148+ /// </para>
149+ /// <para>
150+ /// If left <see langword="null"/>, all supported algorithms are allowed.
151+ /// </para>
152+ /// <para>
84153 /// See <see href="https://www.iana.org/assignments/cose/cose.xhtml#algorithms"/>.
154+ /// </para>
85155 /// </remarks>
86156 public Func < int , bool > ? IsAllowedAlgorithm { get ; set ; }
87157
88158 /// <summary>
89159 /// Gets or sets a function that validates the origin of the request.
90160 /// </summary>
91161 /// <remarks>
92- /// By default, this function disallows cross-origin requests and checks
93- /// that the request's origin header matches the credential's origin.
162+ /// <para>
163+ /// This option applies to both creating a new passkey and requesting an existing passkey.
164+ /// </para>
165+ /// <para>
166+ /// If left <see langword="null"/>, cross-origin requests are disallowed, and the request is only
167+ /// considered valid if the request's origin header matches the credential's origin.
168+ /// </para>
94169 /// </remarks>
95- public Func < PasskeyOriginValidationContext , Task < bool > > ValidateOrigin { get ; set ; } = DefaultValidateOrigin ;
170+ public Func < PasskeyOriginValidationContext , ValueTask < bool > > ? ValidateOrigin { get ; set ; }
96171
97172 /// <summary>
98173 /// Gets or sets a function that verifies the attestation statement of a passkey.
99174 /// </summary>
100175 /// <remarks>
101- /// By default, this function does not perform any verification and always returns <see langword="true"/>.
176+ /// <para>
177+ /// This option only applies when creating a new passkey, and already-registered passkeys are not affected by it.
178+ /// </para>
179+ /// <para>
180+ /// If left <see langword="null"/>, this function does not perform any verification and always returns <see langword="true"/>.
181+ /// </para>
102182 /// </remarks>
103- public Func < PasskeyAttestationStatementVerificationContext , Task < bool > > VerifyAttestationStatement { get ; set ; } = DefaultVerifyAttestationStatement ;
104-
105- private static Task < bool > DefaultValidateOrigin ( PasskeyOriginValidationContext context )
106- {
107- var result = IsValidOrigin ( ) ;
108- return Task . FromResult ( result ) ;
109-
110- bool IsValidOrigin ( )
111- {
112- if ( string . IsNullOrEmpty ( context . Origin ) ||
113- context . CrossOrigin ||
114- ! Uri . TryCreate ( context . Origin , UriKind . Absolute , out var originUri ) )
115- {
116- return false ;
117- }
118-
119- // Uri.Equals correctly handles string comparands.
120- return context . HttpContext . Request . Headers . Origin is [ var origin ] && originUri . Equals ( origin ) ;
121- }
122- }
123-
124- private static Task < bool > DefaultVerifyAttestationStatement ( PasskeyAttestationStatementVerificationContext context )
125- => Task . FromResult ( true ) ;
183+ public Func < PasskeyAttestationStatementVerificationContext , ValueTask < bool > > ? VerifyAttestationStatement { get ; set ; }
126184}
0 commit comments