Table of Contents

HmacAuthenticationOptions Class

Definition

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

Name Description
HmacAuthenticationOptions()

Initializes a new instance of the HmacAuthenticationOptions class.

Properties

Name Description
Algorithm

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

AuthenticationScheme

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

Authenticator

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

Methods

Name Description
ValidateOptions()

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

See Also