Table of Contents

ApiKeySentinelFilter Class

Definition

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

Name Description
ApiKeySentinelFilter(IOptions<ApiKeySentinelOptions>)

Initializes a new instance of the ApiKeySentinelFilter class.

Methods

Name Description
OnAuthorizationAsync(AuthorizationFilterContext)

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

See Also