Table of Contents

BasicAuthenticationOptions Class

Definition

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

Name Description
BasicAuthenticationOptions()

Initializes a new instance of the BasicAuthenticationOptions class.

Properties

Name Description
Authenticator

Gets or sets the function delegate that will perform the authentication from the specified username and password.

Realm

Gets the realm that defines the protection space.

Methods

Name Description
ValidateOptions()

Determines whether the public read-write properties of this instance are in a valid state.

See Also