Table of Contents

Class ApiKeyAuthOptions

Namespace
Virtufin.Api.Auth
Assembly
Virtufin.Api.dll

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

string

Properties

Enabled

Authentication is enforced only when at least one key is configured.

public bool Enabled { get; }

Property Value

bool

Keys

Configured keys, keyed by caller name.

public IReadOnlyDictionary<string, string> Keys { get; init; }

Property Value

IReadOnlyDictionary<string, string>

Methods

FromConfiguration(IConfiguration)

Load keys from configuration (env vars bind as ApiAuth__Keys__<name>).

public static ApiKeyAuthOptions FromConfiguration(IConfiguration configuration)

Parameters

configuration IConfiguration

Returns

ApiKeyAuthOptions

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)

Parameters

presentedKey string
keyName string

Returns

bool