Table of Contents

Class ApiKeySentinelFilter

Namespace
Cuemon.AspNetCore.Mvc.Filters.Headers
Assembly
Cuemon.AspNetCore.Mvc.dll

A filter that confirms request authorization in the form of an API key sentinel.

public class ApiKeySentinelFilter : ConfigurableAsyncAuthorizationFilter<ApiKeySentinelOptions>, IConfigurable<ApiKeySentinelOptions>, IAsyncAuthorizationFilter, IFilterMetadata
Inheritance
ApiKeySentinelFilter
Implements
Inherited Members

Examples

The following example creates directly from configured options.

using System;
using System.Net;
using Cuemon.AspNetCore.Http.Headers;
using Cuemon.AspNetCore.Mvc.Filters.Headers;
using Microsoft.Extensions.Options;

namespace MyApp.Examples;

public static class ApiKeySentinelFilterExample
{
    public static void Demonstrate()
    {
        var options = Options.Create(new ApiKeySentinelOptions
        {
            UseGenericResponse = true,
            GenericClientStatusCode = HttpStatusCode.NotFound,
            GenericClientMessage = "Resource not found."
        });
        options.Value.AllowedKeys.Add("Cuemon-Key");

        var filter = new ApiKeySentinelFilter(options);

        Console.WriteLine(filter.Options.HeaderName);
        Console.WriteLine(filter.Options.AllowedKeys.Count);
    }
}

Constructors

ApiKeySentinelFilter(IOptions<ApiKeySentinelOptions>)

Initializes a new instance of the ApiKeySentinelFilter class.

public ApiKeySentinelFilter(IOptions<ApiKeySentinelOptions> setup)

Parameters

setup IOptions<ApiKeySentinelOptions>

The ApiKeySentinelOptions which need to be configured.

Methods

OnAuthorizationAsync(AuthorizationFilterContext)

Called early in the filter pipeline to confirm request is authorized.

public override Task OnAuthorizationAsync(AuthorizationFilterContext context)

Parameters

context AuthorizationFilterContext

The AuthorizationFilterContext.

Returns

Task

A Task that on completion indicates the filter has executed.

See Also