Class ApiKeyAuthOptions
API-key authentication configuration for the gRPC surface. Keys are named so successful calls can be attributed to a caller in logs. When no keys are configured, authentication is disabled (local dev default).
public sealed class ApiKeyAuthOptions
- Inheritance
-
ApiKeyAuthOptions
- Inherited Members
Fields
KeysSectionName
Configuration section holding the key dictionary (ApiAuth:Keys:<name>).
public const string KeysSectionName = "ApiAuth:Keys"
Field Value
Properties
Enabled
Authentication is enforced only when at least one key is configured.
public bool Enabled { get; }
Property Value
Keys
Configured keys, keyed by caller name.
public IReadOnlyDictionary<string, string> Keys { get; init; }
Property Value
Methods
FromConfiguration(IConfiguration)
Load keys from configuration (env vars bind as ApiAuth__Keys__<name>).
public static ApiKeyAuthOptions FromConfiguration(IConfiguration configuration)
Parameters
configurationIConfiguration
Returns
TryAuthenticate(string?, out string?)
Constant-time match of a presented key against the configured keys. Returns true and the caller name on success; false otherwise.
public bool TryAuthenticate(string? presentedKey, out string? keyName)