HttpBasicAuthenticationOptions Class

Options for HTTP Basic authentication.

public sealed class HttpBasicAuthenticationOptions : AuthenticationSchemeOptions
Inheritance
AuthenticationSchemeOptions HttpBasicAuthenticationOptions

Constructors

NameDescription
HttpBasicAuthenticationOptions()

HttpBasicAuthenticationOptions()

HttpBasicAuthenticationOptions.cs
public HttpBasicAuthenticationOptions()

No documentation is available.

Properties

NameDescription
AllowTwoFactorEnabledAccountsGets 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.
MaxCredentialLengthGets or sets the maximum length (in characters) of the Base64 credential payload. Requests exceeding this limit fail authentication.
RealmGets 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.
ValidateCredentialsGets or sets the delegate used to validate credentials and create the ClaimsPrincipal. Returning null fails authentication.

AllowTwoFactorEnabledAccounts

HttpBasicAuthenticationOptions.cs

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.

public bool AllowTwoFactorEnabledAccounts { get; set; }

Property value

bool

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.

Gets or sets the maximum length (in characters) of the Base64 credential payload. Requests exceeding this limit fail authentication.

public int MaxCredentialLength { get; set; }

Property value

int

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.

public string? Realm { get; set; }

Property value

string?

Exceptions

ArgumentException
The value contains a character that cannot be written to a response header.

Gets or sets the delegate used to validate credentials and create the ClaimsPrincipal. Returning null fails authentication.

public HttpBasicCredentialValidator ValidateCredentials { get; set; }

Property value

HttpBasicCredentialValidator

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

NameDescription
DefaultMaxCredentialLengthThe 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