Skip to content

InMemoryApiKeyStore

Namespace AgentPrism · Assembly AgentPrism.Core.dll

The default implementation that keeps API keys in process memory.

public sealed class InMemoryApiKeyStore : IApiKeyStore

objectInMemoryApiKeyStore

IApiKeyStore

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

For single-process deployments and tests. UsePostgreSql, or the SQL Server or SQLite equivalent, replaces it with SqlApiKeyStore.

Initializes a new in-memory API key store.

public InMemoryApiKeyStore(TimeProvider? timeProvider = null)

timeProvider TimeProvider?

The time provider. Uses TimeProvider.System when omitted.

CreateAsync(ApiKeyDraft, CancellationToken)

Section titled “ CreateAsync(ApiKeyDraft, CancellationToken)”

Generates and stores a new key.

public ValueTask<ApiKeyCreationResult> CreateAsync(ApiKeyDraft draft, CancellationToken cancellationToken = default)

draft ApiKeyDraft

The key’s draft.

cancellationToken CancellationToken

The cancellation token.

ValueTask<ApiKeyCreationResult>

The saved record and the raw key value. The raw value cannot be produced again after this call.

FindByHashAsync(ReadOnlyMemory<byte>, CancellationToken)

Section titled “ FindByHashAsync(ReadOnlyMemory<byte>, CancellationToken)”

Looks up a key by its SHA-256 digest.

public ValueTask<ApiKeyRecord?> FindByHashAsync(ReadOnlyMemory<byte> keyHash, CancellationToken cancellationToken = default)

keyHash ReadOnlyMemory<byte>

The digest of the presented raw value.

cancellationToken CancellationToken

The cancellation token.

ValueTask<ApiKeyRecord?>

The record; null if it does not exist.

No tenant filter is applied: the tenant is the OUTPUT of this call, not its INPUT — while authenticating a request, which tenant it belongs to is not yet known. The lookup always goes through the digest; the raw value never enters any query directly.

HasActiveScopeAsync(ApiKeyScope, CancellationToken)

Section titled “ HasActiveScopeAsync(ApiKeyScope, CancellationToken)”

Reports whether at least one key exists in the system (in any tenant) that carries the given scope, is not revoked, and has not expired.

public ValueTask<bool> HasActiveScopeAsync(ApiKeyScope scope, CancellationToken cancellationToken = default)

scope ApiKeyScope

The scope to look for.

cancellationToken CancellationToken

The cancellation token.

ValueTask<bool>

true if found.

There is deliberately no tenant filter: this is an installation health check, not specific to any tenant — it asks whether the system has at least one valid external:invoke key, so the external surface can be opened TOGETHER with AllowRemoteAccess.

Lists a tenant’s keys. The raw value and digest are not returned.

public ValueTask<IReadOnlyList<ApiKeyRecord>> ListAsync(string tenantId, CancellationToken cancellationToken = default)

tenantId string

The tenant identifier.

cancellationToken CancellationToken

The cancellation token.

ValueTask<IReadOnlyList<ApiKeyRecord>>

The keys, by creation time.

RevokeAsync(string, Guid, CancellationToken)

Section titled “ RevokeAsync(string, Guid, CancellationToken)”

Revokes a key. The row is not DELETED; revoked_at is written.

public ValueTask<bool> RevokeAsync(string tenantId, Guid id, CancellationToken cancellationToken = default)

tenantId string

The tenant the key is bound to.

id Guid

The key identifier.

cancellationToken CancellationToken

The cancellation token.

ValueTask<bool>

true if the key was found in this tenant and revoked.

TouchLastUsedAsync(Guid, DateTimeOffset, CancellationToken)

Section titled “ TouchLastUsedAsync(Guid, DateTimeOffset, CancellationToken)”

Updates the last-used timestamp.

public ValueTask TouchLastUsedAsync(Guid id, DateTimeOffset usedAt, CancellationToken cancellationToken = default)

id Guid

The key identifier.

usedAt DateTimeOffset

The usage time.

cancellationToken CancellationToken

The cancellation token.

ValueTask

The completion task.

There is no tenant filter: the caller (ApiKeyAuthenticator) has already found the key through its digest and RESOLVED the tenant; a second check here is unnecessary — the same reason as IApiKeyStore.FindByHashAsync.