Table of Contents

Class HmacAuthenticationOptions

Namespace
Cuemon.AspNetCore.Authentication.Hmac
Assembly
Cuemon.AspNetCore.Authentication.dll

Configuration options for HmacAuthenticationMiddleware. This class cannot be inherited.

public sealed class HmacAuthenticationOptions : AuthenticationOptions, IValidatableParameterObject, IParameterObject
Inheritance
HmacAuthenticationOptions
Implements
Inherited Members

Examples

The following example demonstrates how to configure HmacAuthenticationOptions for HMAC request signing.

using System;
using System.Security.Claims;
using Cuemon.AspNetCore.Authentication.Hmac;
using Cuemon.Security.Cryptography;

namespace MyApp.Examples;

public static class HmacAuthenticationOptionsExample
{
    public static void Demonstrate()
    {
        var options = new HmacAuthenticationOptions
        {
            AuthenticationScheme = "hmac-docs",
            Algorithm = KeyedCryptoAlgorithm.HmacSha256,
            RequireSecureConnection = false,
            Authenticator = (string clientId, out string clientSecret) =>
            {
                clientSecret = clientId == "Agent-Api" ? "Test" : null;
                return clientSecret == null
                    ? null
                    : new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, clientId) }, "hmac-docs"));
            }
        };

        options.ValidateOptions();

        Console.WriteLine(options.AuthenticationScheme);
    }
}

Constructors

HmacAuthenticationOptions()

Initializes a new instance of the HmacAuthenticationOptions class.

public HmacAuthenticationOptions()

Properties

Algorithm

Gets or sets the algorithm of the HMAC Authentication. Default is HmacSha256.

public KeyedCryptoAlgorithm Algorithm { get; set; }

Property Value

KeyedCryptoAlgorithm

The algorithm of the HMAC Authentication.

AuthenticationScheme

Gets the name of the authentication scheme. Default is Scheme.

public string AuthenticationScheme { get; set; }

Property Value

string

The name of the authentication scheme.

Authenticator

Gets or sets the function delegate that will perform the authentication from the specified publicKey.

public HmacAuthenticator Authenticator { get; set; }

Property Value

HmacAuthenticator

The function delegate that will perform the authentication.

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 - AuthenticationScheme cannot be null, empty or consist only of white-space characters.

See Also