Skip to content

feat(auth): delete one of the signed-in user's passkeys - #637

Merged
Tr00d merged 1 commit into
masterfrom
feat/auth.passkey.delete_passkey
Nov 2, 2026
Merged

Tr00d merged 1 commit into
masterfrom
feat/auth.passkey.delete_passkey

Conversation

@Tr00d

@Tr00d Tr00d commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Summary

A signed-in user can delete one of their own passkeys. This revokes the credential without admin privileges.

Capability: auth.passkey.delete_passkey — Delete Passkey. No capability spec exists for it. Partially addresses #251.

Public API

// IGotrueClient<TUser, TSession>, right after ListPasskeysAsync
Task DeletePasskeyAsync(Guid passkeyId, CancellationToken cancellationToken = default);

// IGotrueApi<TUser, TSession>
Task DeletePasskeyAsync(string jwt, Guid passkeyId, CancellationToken cancellationToken = default);

No new types.

var passkeys = await client.ListPasskeysAsync();
var lost = passkeys.First(passkey => passkey.FriendlyName == "Old laptop");
await client.DeletePasskeyAsync(lost.Id);

Behavior

  • Operation: DELETE /auth/v1/passkeys/{passkey_id}, authenticated with the signed-in user's access token (Authorization: Bearer) and the apikey. The id goes on the path in its canonical lowercase form.
  • Inputs: the passkey id as a Guid, so a malformed or path-escaping id cannot reach the wire. Before the wire the SDK requires the client to be online and a session with an access token to exist.
  • Output: none. The server answers 204 with no body.
  • Failures:
    • Offline → GotrueException, Reason = Offline, no request sent.
    • No session, or a session without an access token → GotrueException, Reason = NoSessionFound, no request sent.
    • 403 insufficient_aal when the user has MFA enabled and the session is not at aal2 → GotrueException with that ErrorCode.
    • 404 validation_failed ("Passkey not found") when the user has no passkey with that id. This is surfaced as a GotrueException (StatusCode 404), not treated as an already-deleted success.
    • 404 passkey_disabled when passkeys are off on the server.
    • Any other server rejection → GotrueException with the server's ErrorCode, through the existing error mapping.
    • No new FailureHint.Reason values.
  • State: none on the client, and the current session is kept. The server records a passkey_deleted audit entry. A gotrue.delete_passkey span parents the HTTP span.

Contract sources: the auth server's handler, since supabase/auth openapi.yaml documents no /passkeys paths:

  • internal/api/passkey_manage.go (PasskeyDelete)
  • passkey_webauthn.go (requirePasskeyManagementAAL)
  • middleware.go (requirePasskeyEnabled)

Behavioral references:

  • supabase-js auth-js/src/GoTrueClient.ts (_deletePasskey)
  • supabase-flutter (d7eb4936) packages/supabase_auth/lib/src/auth_passkey_api.dart (delete())

Deviations from supabase-js

  • No session refresh before the call. supabase-js (_useSession) and supabase-flutter (delete() calls _userAccessToken, which goes through getSession, auth_client.dart:485) refresh an expired session first. This SDK uses the current access token, like ListPasskeysAsync and the recovery-code methods.
  • Guid id. Both references take a string passkeyId.
  • Return value. supabase-js returns { data: null, error }. This returns Task and throws the typed exception on failure.

Tests

Tier Class Pins
E2E DeletePasskeyTests Deleting one of two passkeys leaves only the other. An unknown id answers 404. A TOTP-enrolled user on an aal1 password session gets insufficient_aal. The same user at aal2 (after verifying TOTP) deletes the passkey.
Contract DeletePasskeyContractTests DELETE /passkeys/{id} with bearer + apikey and the canonical id; 204 completes; insufficient_aal, not-found 404 and passkey_disabled surfaced; NoSessionFound (no session / no access token, no request sent); Offline; cancellation reaches the HTTP call; no capture of the caller's context.
Contract ObservabilityContractTests gotrue.delete_passkey domain span parents the DELETE /passkeys/{id} HTTP span.

Changed-line coverage: 100% (9 lines). Mutation: 7/7 tested mutants on changed lines killed, 0 survivors.

Notes

  • The tests reuse the supabase/config.toml passkey block and Gotrue.Tests/Support/SoftwareAuthenticator from feat(auth): list the signed-in user's passkeys #634. The E2E checks deletion through ListPasskeysAsync, which is now on master.
  • Passkeys are seeded before TOTP is enrolled, because the server also requires aal2 to register a passkey once MFA is enabled.
  • Spec gap: the auth OpenAPI does not describe the /passkeys endpoints.

Adds IGotrueClient.DeletePasskeyAsync (DELETE /passkeys/{passkey_id}).

Refs #251
@Tr00d
Tr00d marked this pull request as ready for review November 2, 2026 14:51
@Tr00d
Tr00d merged commit a279fa8 into master Nov 2, 2026
6 checks passed
@Tr00d
Tr00d deleted the feat/auth.passkey.delete_passkey branch November 2, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant