Table of Contents

Class HmacAuthenticationMiddleware

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

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

HmacAuthenticationMiddleware(RequestDelegate, IOptions<HmacAuthenticationOptions>)

Initializes a new instance of the HmacAuthenticationMiddleware class.

public HmacAuthenticationMiddleware(RequestDelegate next, IOptions<HmacAuthenticationOptions> setup)

Parameters

next RequestDelegate

The delegate of the request pipeline to invoke.

setup IOptions<HmacAuthenticationOptions>

The HmacAuthenticationOptions which need to be configured.

HmacAuthenticationMiddleware(RequestDelegate, Action<HmacAuthenticationOptions>)

Initializes a new instance of the HmacAuthenticationMiddleware class.

public HmacAuthenticationMiddleware(RequestDelegate next, Action<HmacAuthenticationOptions> setup)

Parameters

next RequestDelegate

The delegate of the request pipeline to invoke.

setup Action<HmacAuthenticationOptions>

The middleware HmacAuthenticationOptions which need to be configured.

Methods

InvokeAsync(HttpContext)

public override Task InvokeAsync(HttpContext context)

Parameters

context HttpContext

The context of the current request.

Returns

Task

A task that represents the execution of this middleware.