Table of Contents

Class ApiKeyRotation

Namespace
JD.AI.Core.Security
Assembly
JD.AI.Core.dll

Manages API key lifecycle: generation, rotation, and expiry tracking.

public sealed class ApiKeyRotation
Inheritance
ApiKeyRotation
Inherited Members

Properties

ActiveKeyCount

Number of active (non-expired, non-revoked) keys.

public int ActiveKeyCount { get; }

Property Value

int

Methods

GenerateKey(string, GatewayRole, TimeSpan?)

Generates a new API key with optional expiry.

public string GenerateKey(string name, GatewayRole role = GatewayRole.User, TimeSpan? expiry = null)

Parameters

name string
role GatewayRole
expiry TimeSpan?

Returns

string

The generated API key string.

GetAllKeys()

Gets all key records (for admin/audit purposes).

public IReadOnlyList<ApiKeyRecord> GetAllKeys()

Returns

IReadOnlyList<ApiKeyRecord>

RevokeKey(string)

Explicitly revokes a key.

public bool RevokeKey(string key)

Parameters

key string

Returns

bool

RotateKey(string, TimeSpan?)

Rotates a key: generates a new key and revokes the old one. Returns the new key, or null if the old key was not found.

public string? RotateKey(string oldKey, TimeSpan? newExpiry = null)

Parameters

oldKey string
newExpiry TimeSpan?

Returns

string

TouchKey(string)

Records usage of a key (last used timestamp and increment counter). Returns true if the key was found and updated, false otherwise.

public bool TouchKey(string key)

Parameters

key string

Returns

bool

Validate(string)

Validates and retrieves a key record. Returns null if key is invalid, expired, or revoked.

public ApiKeyRecord? Validate(string key)

Parameters

key string

Returns

ApiKeyRecord