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
nextRequestDelegateThe delegate of the request pipeline to invoke.
setupIOptions<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
nextRequestDelegateThe delegate of the request pipeline to invoke.
setupAction<HmacAuthenticationOptions>The middleware HmacAuthenticationOptions which need to be configured.
Methods
InvokeAsync(HttpContext)
Executes the HmacAuthenticationMiddleware.
public override Task InvokeAsync(HttpContext context)
Parameters
contextHttpContextThe context of the current request.
Returns
- Task
A task that represents the execution of this middleware.