Interface IApiKeyRepository
Repository interface for API key persistence. Auto-registered by Tharga.MongoDB.
public interface IApiKeyRepository : IRepository
Methods
AddAsync(ApiKeyEntity)
Persists a new API key entity and returns it.
Task<ApiKeyEntity> AddAsync(ApiKeyEntity apiKeyEntity)
Parameters
apiKeyEntityApiKeyEntity
Returns
CleanLegacyTagsAsync()
One-time migration: removes the legacy Tags field from documents where it is still stored as a
BSON document (the pre-#75 Dictionary<string,string> representation). Runs server-side and
returns the number of documents cleaned. Safe to run repeatedly. Reading is already tolerant of the
legacy shape; this just purges it permanently.
Task<long> CleanLegacyTagsAsync()
Returns
DeleteAsync(string)
Deletes the API key entity with the specified key.
Task DeleteAsync(string key)
Parameters
keystring
Returns
GetAsync()
Returns all stored API key entities.
IAsyncEnumerable<ApiKeyEntity> GetAsync()
Returns
GetAsync(string)
Returns the API key entity with the specified key, or null if not found.
Task<ApiKeyEntity> GetAsync(string key)
Parameters
keystring
Returns
GetByPrefixAsync(string)
Returns API key entities matching the given prefix.
IAsyncEnumerable<ApiKeyEntity> GetByPrefixAsync(string prefix)
Parameters
prefixstring
Returns
LockKeyAsync(string)
Marks the API key as locked so it cannot be used.
Task LockKeyAsync(string key)
Parameters
keystring
Returns
PurgeExpiredAsync()
Deletes all expired API key entities.
Task PurgeExpiredAsync()
Returns
SetDisabledAsync(string, DateTime?, string)
Marks the key disabled, or clears the mark when disabledAtUtc is null.
A disabled key is refused at authentication.
Task SetDisabledAsync(string key, DateTime? disabledAtUtc, string disabledBy)
Parameters
Returns
SetLastUsedAsync(string, DateTime)
Sets the "last used" timestamp for the key via a targeted field update (no full-document replace).
Task SetLastUsedAsync(string key, DateTime lastUsedAtUtc)
Parameters
Returns
UpdateAsync(string, ApiKeyEntity)
Replaces the API key entity identified by the given key.
Task UpdateAsync(string key, ApiKeyEntity apiKeyEntity)
Parameters
keystringapiKeyEntityApiKeyEntity