HttpBasicAuthenticationOptions Class
Options for HTTP Basic authentication.
public sealed class HttpBasicAuthenticationOptions : AuthenticationSchemeOptions- Inheritance
AuthenticationSchemeOptionsHttpBasicAuthenticationOptions
Constructors
| Name | Description |
|---|---|
| HttpBasicAuthenticationOptions() |
HttpBasicAuthenticationOptions()
HttpBasicAuthenticationOptions.cspublic HttpBasicAuthenticationOptions()No documentation is available.
Properties
| Name | Description |
|---|---|
| AllowTwoFactorEnabledAccounts | Gets or sets a value indicating whether the ASP.NET Core Identity integration authenticates accounts that require two-factor authentication with their password alone. The default is false: HTTP Basic cannot provide a second factor, so these accounts are rejected. |
| MaxCredentialLength | Gets or sets the maximum length (in characters) of the Base64 credential payload. Requests exceeding this limit fail authentication. |
| Realm | Gets or sets the value of the realm parameter in the WWW-Authenticate header. Set to null to omit the parameter. Only printable ASCII characters (U+0020 to U+007E) are allowed, as required by RFC 7617. |
| ValidateCredentials | Gets or sets the delegate used to validate credentials and create the ClaimsPrincipal. Returning null fails authentication. |
AllowTwoFactorEnabledAccounts
HttpBasicAuthenticationOptions.csGets or sets a value indicating whether the ASP.NET Core Identity integration authenticates accounts that require two-factor authentication with their password alone. The default is false: HTTP Basic cannot provide a second factor, so these accounts are rejected.
public bool AllowTwoFactorEnabledAccounts { get; set; }Property value
Remarks
Enabling this lets anyone who knows the password of such an account skip its second factor. It is only used by AddHttpBasicIdentity, and has no effect on a custom HttpBasicAuthenticationOptions.ValidateCredentials delegate.
MaxCredentialLength
HttpBasicAuthenticationOptions.csGets or sets the value of the realm parameter in the WWW-Authenticate header. Set to null to omit the parameter. Only printable ASCII characters (U+0020 to U+007E) are allowed, as required by RFC 7617.
public string? Realm { get; set; }Property value
Exceptions
ArgumentException- The value contains a character that cannot be written to a response header.
ValidateCredentials
HttpBasicAuthenticationOptions.csGets or sets the delegate used to validate credentials and create the ClaimsPrincipal. Returning null fails authentication.
public HttpBasicCredentialValidator ValidateCredentials { get; set; }Property value
Remarks
Schemes registered with AddHttpBasicIdentity set this property to an ASP.NET Core Identity validator. Changing it for such a scheme fails options validation instead of replacing or being replaced by the Identity validator.
Constants
| Name | Description |
|---|---|
| DefaultMaxCredentialLength | The default maximum length (in characters) of the Base64 credential payload. |
DefaultMaxCredentialLength
The default maximum length (in characters) of the Base64 credential payload.
public const int DefaultMaxCredentialLength = 4096