Skip to main content
Version: 4.2

IPasskeyCredentialStore

Namespace: Wisej.Web

Assembly: Wisej.Framework (4.2.0.0)

The durable credential store Passkey requires. Wisej.NET has no account database, so the application implements this over its own storage and registers it with Services; the component resolves it at the start of every operation and fails with StoreUnavailable before showing any prompt when it is missing.

4.2.0+
public interface IPasskeyCredentialStore

Scope. Every method takes the normalized relying party id and answers only for rows with that id: a credential id or a user handle meaningful under one relying party is never resolved under another, even when one database serves several hosts. Credential ids and user handles are compared by value. User ids are compared ordinally: case, accents and white space all count. The component leaves the ownership of a rename or a delete to the store's own comparison of the user id, so a store over SQL declares every UserId column with a binary collation; under a case-insensitive one, an account whose id differs from another's only in case could rename or delete the other's passkeys.

Lifetime and threads. Register the implementation as a Shared service, or through an application-supplied IServiceProvider: one instance serves every session and every request at once and must be thread-safe. A session-scoped store cannot serve sign-in, which runs before the session has an identity. Credential data is never kept in a Wisej service scope; the store is an adapter over durable storage.

Outcomes, not exceptions. A missing row is a return value — false, null or NotFound — never an exception. An exception thrown by any method means the store itself failed; the component reports it as StoreFailed with the exception attached and commits nothing. Keep credential ids, user handles and key material out of those exceptions' messages: the component removes the base64 renderings it recognizes before an exception leaves it, but a value in any other rendering, such as a list of byte values or hexadecimal with separators, reaches the application's handlers as the store wrote it.

Object ownership. Returned records and arrays are snapshots. The component validates and deep-copies them before use and never exposes a store-owned instance. Implementations must not rely on later mutations of an object they returned or were passed; persistence happens in the method call itself.

Cancellation. Every method takes a CancellationToken last, observes it where its storage can, and may throw OperationCanceledException when it is canceled; the component treats that as cancellation, not as a store failure.

The framework ships no implementation. The QA suite carries an in-memory store for tests only; a durable sample belongs to the application documentation.

Methods​

Instance member AddCredentialAsync(credential, cancellationToken)​

Stores a new credential.

ParameterTypeDescription
credentialPasskeyCredentialThe verified credential, every member set.
cancellationTokenCancellationTokenCancels the call.

Returns: Task<Boolean>. true when the row was inserted; false when a row with the same RelyingPartyId and CredentialId already exists, in which case nothing was written.

Unique insert, never an upsert: an existing row keeps its key and its account whatever this call carries, and two concurrent inserts of the same id leave exactly one row. The component reports false as CredentialExists. The store may assign ConcurrencyToken on insert; a token it assigns differs from every token an earlier row with the same id carried.

Observe cancellationToken only until the row is durable: once the insert has committed, return true rather than throw. The component treats a true result as the end of the registration, which then completes even if it was canceled, replaced or its component disposed while this call was in flight.

Instance member CommitAuthenticationAsync(update, cancellationToken)​

Moves an existing credential to the authentication state of one verified assertion, only if the row is still the one the ceremony read.

ParameterTypeDescription
updatePasskeyAuthenticationUpdateThe row to update, the expected state, and the new state.
cancellationTokenCancellationTokenCancels the call.

Returns: Task<PasskeyCommitResult>. Updated when the row existed, its SignCount equalled ExpectedSignCount (and, for a store that issues tokens, its ConcurrencyToken equalled ExpectedConcurrencyToken) and the new values were written; Conflict when the row exists but no longer matches; NotFound when no such row exists.

Atomic compare-and-update on an existing row: the comparison and the write are one operation, so two assertions that cross commit in some order and the loser sees Conflict, and a credential deleted after the ceremony read it is never recreated. A row deleted and inserted again under the same id is not the row the ceremony read: answer Conflict or NotFound for it, never Updated. A store that issues concurrency tokens does this by giving every inserted row a token no earlier row under that id carried (a row version, fresh random bytes); a per-row version that restarts on insert does not, and neither does a store without tokens when the counter is unchanged. A store that issues tokens gives one to every row, rows written before it had a token included, and compares a null token and an empty one as the same missing token: the component hands back a record that carried none as an empty array, never as null. The write changes exactly SignCount, BackedUp, LastUsedAt and — to its stored value OR UserVerified — UserVerified, and rotates the concurrency token when the store uses one. It never touches the key, the algorithm, the account binding, the user handle, the name, the creation time or the registration evidence.

The component never calls this with a counter below the expected one; a store may refuse such an update anyway. The component calls this only after every protocol check and the Authenticating event have passed, and reports Authenticated only after it returns Updated.

Instance member DeleteCredentialAsync(relyingPartyId, userId, credentialId, cancellationToken)​

Removes a credential.

ParameterTypeDescription
relyingPartyIdStringThe normalized relying party id.
userIdStringThe application user id that must own the credential.
credentialIdByte[]The credential id, compared by value.
cancellationTokenCancellationTokenCancels the call.

Returns: Task<Boolean>. true when a row with that relying party id, credential id and owner existed and was removed; false when none does, including when the credential belongs to another account.

Removal is final: an authentication in flight against the removed row commits as NotFound and fails. Removing the row does not remove the passkey from the user's device or password manager; the application tells the user so.

Instance member FindCredentialAsync(relyingPartyId, credentialId, cancellationToken)​

Returns the credential with the specified id, whichever account owns it.

ParameterTypeDescription
relyingPartyIdStringThe normalized relying party id.
credentialIdByte[]The credential id, compared by value.
cancellationTokenCancellationTokenCancels the call.

Returns: Task<PasskeyCredential>. The credential, or null when none has that id under this relying party.

The lookup a discoverable (usernameless) authentication needs: the account is not known until the row is found. A known-user authentication uses it too and then checks UserId against the account named. After a commit Conflict the component calls it again and fails with CredentialMismatch unless the account, the key, the algorithm, the user handle, the backup eligibility and the evidence equal what the first call returned.

Instance member GetCredentialsAsync(relyingPartyId, userId, cancellationToken)​

Returns every credential registered for the account.

ParameterTypeDescription
relyingPartyIdStringThe normalized relying party id.
userIdStringThe application user id.
cancellationTokenCancellationTokenCancels the call.

Returns: Task<PasskeyCredential[]>. The account's credentials, in any order; an empty array when it has none. Never null.

Used for excludeCredentials at registration, for allowCredentials on a known-user authentication, and by GetCredentialsAsync.

Instance member GetOrCreateUserHandleAsync(relyingPartyId, userId, newUserHandle, cancellationToken)​

Returns the user handle stored for the account, storing newUserHandle first when the account has none.

ParameterTypeDescription
relyingPartyIdStringThe normalized relying party id.
userIdStringThe application user id.
newUserHandleByte[]A freshly generated 64-byte random handle to store when the account has none yet. The component generates it; the store never derives one from the user id, a name or an e-mail address.
cancellationTokenCancellationTokenCancels the call.

Returns: Task<Byte[]>. The handle now stored for the account: the existing one, or newUserHandle when it was just stored. Never null or empty.

Atomic: two concurrent calls for the same account return the same handle, and an account never ends up with two. The handle is stable for the life of the account and shared by every credential of that account under this relying party.

Instance member RenameCredentialAsync(relyingPartyId, userId, credentialId, name, cancellationToken)​

Changes the user-editable name of a credential.

ParameterTypeDescription
relyingPartyIdStringThe normalized relying party id.
userIdStringThe application user id that must own the credential.
credentialIdByte[]The credential id, compared by value.
nameStringThe new name, already validated by the component; may be null to clear it.
cancellationTokenCancellationTokenCancels the call.

Returns: Task<Boolean>. true when a row with that relying party id, credential id and owner existed and was renamed; false when none does, including when the credential belongs to another account.

Changes Name only, and rotates the concurrency token when the store uses one, so an authentication that read the row before the rename commits as Conflict rather than overwriting the name.