Table of Contents

HmacAuthenticationMiddleware Class

Definition

Provides a HTTP HMAC Authentication middleware implementation for ASP.NET Core.

public class HmacAuthenticationMiddleware : ConfigurableMiddleware<HmacAuthenticationOptions>, IConfigurable<HmacAuthenticationOptions>
Inheritance
HmacAuthenticationMiddleware
Implements
Inherited Members

Examples

The following example demonstrates how to construct HmacAuthenticationMiddleware with inline option setup.

using System;
using System.Security.Claims;
using System.Threading.Tasks;
using Cuemon.AspNetCore.Authentication.Hmac;

namespace MyApp.Examples;

public static class HmacAuthenticationMiddlewareExample
{
    public static void Demonstrate()
    {
        var middleware = new HmacAuthenticationMiddleware(_ => Task.CompletedTask, options =>
        {
            options.AuthenticationScheme = "hmac-docs";
            options.RequireSecureConnection = false;
            options.Authenticator = (string clientId, out string clientSecret) =>
            {
                clientSecret = clientId == "Agent-Api" ? "Test" : null;
                return clientSecret == null ? null : new ClaimsPrincipal(new ClaimsIdentity());
            };
        });

        Console.WriteLine(middleware.Options.AuthenticationScheme);
    }
}

Constructors

Name Description
HmacAuthenticationMiddleware(RequestDelegate, IOptions<HmacAuthenticationOptions>)

Initializes a new instance of the HmacAuthenticationMiddleware class.

HmacAuthenticationMiddleware(RequestDelegate, Action<HmacAuthenticationOptions>)

Initializes a new instance of the HmacAuthenticationMiddleware class.

Methods

Name Description
InvokeAsync(HttpContext)

Executes the HmacAuthenticationMiddleware.