Skip to content

feat(auth): list a user's passkeys as an admin - #651

Merged
Tr00d merged 2 commits into
masterfrom
feat/auth.passkey_admin.list_passkeys
Nov 3, 2026
Merged

Tr00d merged 2 commits into
masterfrom
feat/auth.passkey_admin.list_passkeys

Conversation

@Tr00d

@Tr00d Tr00d commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

An admin client can list the passkeys a user has registered, with their names and when they were created and last used.

Capability: auth.passkey_admin.list_passkeys — Admin List Passkeys. No capability spec exists.

Public API

// IGotrueAdminClient<TUser> / AdminClient
Task<IReadOnlyList<Passkey>> ListPasskeysAsync(Guid userId, CancellationToken cancellationToken = default);

// IGotrueApi<TUser, TSession> / Api (service-key twin)
Task<IReadOnlyList<Passkey>> AdminListPasskeysAsync(string jwt, Guid userId, CancellationToken cancellationToken = default);

// FailureHint.Reason
UserNotFound = 24

Passkey (Common/, unshipped) is reused unchanged; its summary now says "registered by a user" instead of "by the signed-in user".

var admin = new AdminClient(serviceRoleKey, new ClientOptions { Url = authUrl });
var passkeys = await admin.ListPasskeysAsync(userId);

Behavior

  • Operation: GET /admin/users/{user_id}/passkeys with a full-access key (service_role) as Bearer.
  • Inputs: userId is a Guid, so it is always a valid path segment; no checks before the wire. No query, no body.
  • Outputs: the user's passkeys, oldest first (the server orders by created_at). An empty array, null or absent body gives an empty list. Absent friendly_name / last_used_at map to null.
  • Failures (GotrueException):
    • 401 no_authorization, 403 bad_jwt / not_admin: Reason.AdminTokenRequired.
    • 404 user_not_found: Reason.UserNotFound.
    • The admin route is not gated by requirePasskeyEnabled, so passkey_disabled cannot occur.
  • State: none.

user_not_found is mapped globally in FailureHint. Every call answering it (GetUserById, UpdateFactorAsync, DeleteUser, admin SignOutAsync, …) now reports Reason.UserNotFound instead of Reason.Unknown; ErrorCode is unchanged.

Deviations from supabase-js

  • Positional Guid userId instead of { userId } with a runtime UUID check: the type guarantees the UUID.
  • Returns the typed list and throws GotrueException instead of { data, error }.
  • Flat on the admin client, like ListFactors / UpdateFactorAsync, instead of an admin.passkey sub-object.
  • The IGotrueApi twin is named AdminListPasskeysAsync, not ListPasskeysAsync. An overload beside the user-level ListPasskeysAsync(string jwt, CancellationToken = default) trips RS0026 (multiple public overloads with optional parameters), and "User" would be ambiguous with that user-level operation, which lists the signed-in user's passkeys. The Admin prefix is applied on IGotrueApi only where an admin twin collides with a user-level operation, so released admin twins stay unprefixed.

Tests

Tier Class Pins
E2E AdminListPasskeysTests seeded passkeys listed oldest first; empty for a user without passkeys; UserNotFound for an unknown user; AdminTokenRequired for the anon key
Contract AdminListPasskeysContractTests method, path and service-role Bearer; list mapping in server order; empty array and null body; user_not_found and not_admin mapping; cancellation before the wire; no context capture
Contract FailureHintTests user_not_found maps to Reason.UserNotFound

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

Notes

  • No supabase/config.toml change: the admin route is served regardless of [auth.passkey]; the existing passkey settings are only needed to seed passkeys through the registration ceremony in E2E.
  • The auth OpenAPI spec documents no passkey endpoint; the contract comes from supabase/auth internal/api/passkey_admin.go (served since gotrue v2.197.0 at the latest).

@Tr00d
Tr00d marked this pull request as ready for review November 3, 2026 10:48
@Tr00d
Tr00d merged commit c9f335f into master Nov 3, 2026
6 checks passed
@Tr00d
Tr00d deleted the feat/auth.passkey_admin.list_passkeys branch November 3, 2026 10:48
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