Class BasicAuthenticationOptions
- Namespace
- Cuemon.AspNetCore.Authentication.Basic
- Assembly
- Cuemon.AspNetCore.Authentication.dll
Configuration options for BasicAuthenticationMiddleware. This class cannot be inherited.
public sealed class BasicAuthenticationOptions : AuthenticationOptions, IValidatableParameterObject, IParameterObject
- Inheritance
-
BasicAuthenticationOptions
- Implements
- Inherited Members
Examples
The following example demonstrates how to configure BasicAuthenticationOptions with a realm and authenticator delegate.
using System;
using System.Security.Claims;
using Cuemon.AspNetCore.Authentication.Basic;
namespace MyApp.Examples;
public static class BasicAuthenticationOptionsExample
{
public static void Demonstrate()
{
var options = new BasicAuthenticationOptions
{
Realm = "docs-example",
RequireSecureConnection = false,
Authenticator = (username, password) =>
{
if (username == "Agent" && password == "Test")
{
return new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, username) }, BasicAuthorizationHeader.Scheme));
}
return null;
}
};
options.ValidateOptions();
Console.WriteLine(options.Realm);
}
}
Constructors
BasicAuthenticationOptions()
Initializes a new instance of the BasicAuthenticationOptions class.
public BasicAuthenticationOptions()
Remarks
The following table shows the initial property values for an instance of BasicAuthenticationOptions.
| Property | Initial Value |
|---|---|
| Authenticator | null |
| Realm | AuthenticationServer |
Properties
Authenticator
Gets or sets the function delegate that will perform the authentication from the specified username and password.
public BasicAuthenticator Authenticator { get; set; }
Property Value
- BasicAuthenticator
The function delegate that will perform the authentication.
Realm
Gets the realm that defines the protection space.
public string Realm { get; set; }
Property Value
- string
The realm that defines the protection space.
Methods
ValidateOptions()
Determines whether the public read-write properties of this instance are in a valid state.
public override void ValidateOptions()
Remarks
This method is expected to throw exceptions when one or more conditions fails to be in a valid state.
Exceptions
- InvalidOperationException
Authenticator cannot be null - or - Realm cannot be null, empty or consist only of white-space characters.