|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +namespace Microsoft.AspNetCore.Identity; |
| 5 | + |
| 6 | +/// <summary> |
| 7 | +/// Specifies options for passkey requirements. |
| 8 | +/// </summary> |
| 9 | +public class IdentityPasskeyOptions |
| 10 | +{ |
| 11 | + /// <summary> |
| 12 | + /// Gets or sets the time that the browser should wait for the authenticator to provide a passkey. |
| 13 | + /// </summary> |
| 14 | + /// <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> |
| 20 | + /// The default value is 5 minutes. |
| 21 | + /// </para> |
| 22 | + /// <para> |
| 23 | + /// See <see href="https://www.w3.org/TR/webauthn-3/#dom-publickeycredentialcreationoptions-timeout"/> |
| 24 | + /// and <see href="https://www.w3.org/TR/webauthn-3/#dom-publickeycredentialrequestoptions-timeout"/>. |
| 25 | + /// </para> |
| 26 | + /// </remarks> |
| 27 | + public TimeSpan AuthenticatorTimeout { get; set; } = TimeSpan.FromMinutes(5); |
| 28 | + |
| 29 | + /// <summary> |
| 30 | + /// Gets or sets the size of the challenge in bytes sent to the client during attestation and assertion. |
| 31 | + /// </summary> |
| 32 | + /// <remarks> |
| 33 | + /// <para> |
| 34 | + /// This option applies to both creating a new passkey and requesting an existing passkey. |
| 35 | + /// </para> |
| 36 | + /// <para> |
| 37 | + /// The default value is 32 bytes. |
| 38 | + /// </para> |
| 39 | + /// <para> |
| 40 | + /// See <see href="https://www.w3.org/TR/webauthn-3/#dom-publickeycredentialcreationoptions-challenge"/> |
| 41 | + /// and <see href="https://www.w3.org/TR/webauthn-3/#dom-publickeycredentialrequestoptions-challenge"/>. |
| 42 | + /// </para> |
| 43 | + /// </remarks> |
| 44 | + public int ChallengeSize { get; set; } = 32; |
| 45 | + |
| 46 | + /// <summary> |
| 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. |
| 49 | + /// </summary> |
| 50 | + /// <remarks> |
| 51 | + /// <para> |
| 52 | + /// This option applies to both creating a new passkey and requesting an existing passkey. |
| 53 | + /// </para> |
| 54 | + /// <para> |
| 55 | + /// If left <see langword="null"/>, the server's origin may be used instead. |
| 56 | + /// </para> |
| 57 | + /// <para> |
| 58 | + /// See <see href="https://www.w3.org/TR/webauthn-3/#rp-id"/>. |
| 59 | + /// </para> |
| 60 | + /// </remarks> |
| 61 | + public string? ServerDomain { get; set; } |
| 62 | + |
| 63 | + /// <summary> |
| 64 | + /// Gets or sets the user verification requirement. |
| 65 | + /// </summary> |
| 66 | + /// <remarks> |
| 67 | + /// <para> |
| 68 | + /// This option applies to both creating a new passkey and requesting an existing passkey. |
| 69 | + /// </para> |
| 70 | + /// <para> |
| 71 | + /// Possible values are "required", "preferred", and "discouraged". |
| 72 | + /// </para> |
| 73 | + /// <para> |
| 74 | + /// 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> |
| 79 | + /// </remarks> |
| 80 | + public string? UserVerificationRequirement { get; set; } |
| 81 | + |
| 82 | + /// <summary> |
| 83 | + /// Gets or sets the extent to which the server desires to create a client-side discoverable credential. |
| 84 | + /// </summary> |
| 85 | + /// <remarks> |
| 86 | + /// <para> |
| 87 | + /// This option only applies when creating a new passkey, and is not enforced on the server. |
| 88 | + /// </para> |
| 89 | + /// <para> |
| 90 | + /// Possible values are "discouraged", "preferred", or "required". |
| 91 | + /// </para> |
| 92 | + /// <para> |
| 93 | + /// 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> |
| 98 | + /// </remarks> |
| 99 | + public string? ResidentKeyRequirement { get; set; } |
| 100 | + |
| 101 | + /// <summary> |
| 102 | + /// Gets or sets the attestation conveyance preference. |
| 103 | + /// </summary> |
| 104 | + /// <remarks> |
| 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> |
| 114 | + /// 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> |
| 119 | + /// </remarks> |
| 120 | + public string? AttestationConveyancePreference { get; set; } |
| 121 | + |
| 122 | + /// <summary> |
| 123 | + /// Gets or sets the allowed authenticator attachment. |
| 124 | + /// </summary> |
| 125 | + /// <remarks> |
| 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> |
| 133 | + /// 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> |
| 138 | + /// </remarks> |
| 139 | + public string? AuthenticatorAttachment { get; set; } |
| 140 | + |
| 141 | + /// <summary> |
| 142 | + /// Gets or sets a function that determines whether the given COSE algorithm identifier |
| 143 | + /// is allowed for passkey operations. |
| 144 | + /// </summary> |
| 145 | + /// <remarks> |
| 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> |
| 153 | + /// See <see href="https://www.iana.org/assignments/cose/cose.xhtml#algorithms"/>. |
| 154 | + /// </para> |
| 155 | + /// </remarks> |
| 156 | + public Func<int, bool>? IsAllowedAlgorithm { get; set; } |
| 157 | + |
| 158 | + /// <summary> |
| 159 | + /// Gets or sets a function that validates the origin of the request. |
| 160 | + /// </summary> |
| 161 | + /// <remarks> |
| 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> |
| 169 | + /// </remarks> |
| 170 | + public Func<PasskeyOriginValidationContext, ValueTask<bool>>? ValidateOrigin { get; set; } |
| 171 | + |
| 172 | + /// <summary> |
| 173 | + /// Gets or sets a function that verifies the attestation statement of a passkey. |
| 174 | + /// </summary> |
| 175 | + /// <remarks> |
| 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> |
| 182 | + /// </remarks> |
| 183 | + public Func<PasskeyAttestationStatementVerificationContext, ValueTask<bool>>? VerifyAttestationStatement { get; set; } |
| 184 | +} |
0 commit comments