Class ApiKeyRotation
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
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
namestringroleGatewayRoleexpiryTimeSpan?
Returns
- string
The generated API key string.
GetAllKeys()
Gets all key records (for admin/audit purposes).
public IReadOnlyList<ApiKeyRecord> GetAllKeys()
Returns
RevokeKey(string)
Explicitly revokes a key.
public bool RevokeKey(string key)
Parameters
keystring
Returns
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
Returns
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
keystring
Returns
Validate(string)
Validates and retrieves a key record. Returns null if key is invalid, expired, or revoked.
public ApiKeyRecord? Validate(string key)
Parameters
keystring