ApiKeySentinelOptions Class
Definition
- Namespace
- Cuemon.AspNetCore.Http.Headers
- Assemblies
- Cuemon.AspNetCore.dll
Configuration options for ApiKeySentinelMiddleware and related.
public class ApiKeySentinelOptions : IValidatableParameterObject, IParameterObject
- Inheritance
-
objectApiKeySentinelOptions
- Implements
Examples
The following example demonstrates configuring API key sentinel options.
using System;
using System.Collections.Generic;
namespace Cuemon.AspNetCore.Http.Headers;
public static class ApiKeySentinelOptionsExample
{
public static void Demonstrate()
{
var options = new ApiKeySentinelOptions
{
AllowedKeys = new List<string> { "secret-key" }
};
options.ValidateOptions();
using var response = options.ResponseHandler("wrong-key");
var message = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
Console.WriteLine(message);
}
}
Constructors
| Name | Description |
|---|---|
| ApiKeySentinelOptions() | Initializes a new instance of the ApiKeySentinelOptions class. |
Properties
| Name | Description |
|---|---|
| AllowedKeys | Gets or sets a list of whitelisted API keys. |
| ForbiddenMessage | Gets or sets the message of a request without a valid HeaderName. |
| GenericClientMessage | Gets or sets the generic message of a request without a valid key in AllowedKeys. |
| GenericClientStatusCode | Gets or sets the generic status code of a request without a valid key in AllowedKeys. |
| HeaderName | Gets or sets the name of the API key HTTP header. |
| ResponseHandler | Gets or sets the function delegate that configures the response in the form of a HttpResponseMessage. |
| UseGenericResponse | Gets or sets a value indicating whether the produced ResponseHandler should be as neutral as possible. |
Methods
| Name | Description |
|---|---|
| ValidateOptions() | Determines whether the public read-write properties of this instance are in a valid state. |