API key authentication from Regira.Security.Authentication — for machine callers that cannot perform an interactive sign-in.
| Property | Type | Default | Description |
|---|---|---|---|
ApiKeyHeaderName |
string |
"X-Api-Key" |
Request header name |
AuthenticationType |
string |
"ApiKey" |
Authentication type string |
Task<ApiKeyOwner?> FindByOwner(string id);
Task<ApiKeyOwner?> FindByKey(string apiKey);
Task<bool> Validate(string id, string apiKey);
| Property | Type | Description |
|---|---|---|
OwnerId |
string |
Owner identifier |
Key |
string |
API key value |
Roles |
ICollection<string> |
Roles assigned to this key |
Claims |
ICollection<ApiKeyOwner.Claim> |
Extra claims (Type / Value pairs) added to the principal |
var services = new ServiceCollection();
IConfiguration configuration = new ConfigurationManager();
// In-memory keys from code
services.AddApiKeyAuthentication()
.AddInMemoryApiKeyAuthentication(new[]
{
new ApiKeyOwner { OwnerId = "client-a", Key = "key-abc", Roles = ["read"] }
});
// From appsettings.json
var keys = configuration.GetSection(AuthenticationSections.ApiKeys).ToApiKeyOwners();
services.AddApiKeyAuthentication()
.AddInMemoryApiKeyAuthentication(keys);
appsettings.json shape — an array, each entry carrying its own OwnerId. ToApiKeyOwners() requires both
fields, so an object keyed by owner name throws InvalidOperationException at startup:
"ApiKeys": [
{ "OwnerId": "client-a", "Key": "key-abc", "Roles": ["read", "write"] }
]
Apache License 2.0 — this package contains no license validation and no runtime limits. See LICENSE. A few companion packages are commercially licensed with a free tier; see the licensing overview.