Skip to content

Add passkey endpoints to MapIdentityApi - #68198

Merged
rolandVi merged 11 commits into
dotnet:mainfrom
rolandVi:passkeys/identity-api-endpoints
Sep 22, 2026
Merged

rolandVi merged 11 commits into
dotnet:mainfrom
rolandVi:passkeys/identity-api-endpoints

Conversation

@rolandVi

@rolandVi rolandVi commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

API proposal in #68197.

SPA and mobile apps that use MapIdentityApi() can now register a passkey, sign in with one, and list, rename and revoke the ones on their account. Today those endpoints only do passwords, so a JavaScript or MAUI client either drops passkeys or hand-writes both WebAuthn ceremonies against SignInManager itself, including the challenge state that has to survive between the two requests.

Design notes

/passkeys/requestOptions returns an empty allowCredentials. Filling it with the account's credential IDs whenever the email matched made the endpoint an enumeration oracle: a populated list is a hard yes, and it hands out the credential IDs and transport hints with it. Empty says nothing either way, and sign-in falls back to discoverable credentials.

The options endpoints return the handler's JSON verbatim instead of round-tripping it through a DTO, so an app's JsonNamingPolicy cannot rename properties whose names WebAuthn fixes.

Registration compares the attested user entity ID against the signed-in user before storing, so a client cannot register a passkey onto another account by replaying someone else's attestation state.

Rename and delete resolve the user, then look the credential up scoped to that user, and 404 before mutating anything. This is load-bearing rather than tidy: UserStore.AddOrUpdatePasskeyAsync resolves a credential ID globally with no user filter, and RemovePasskeyCoreAsync has no existence check, so trusting the route value would be an IDOR on rename and a 200 that deleted nothing on delete. Unknown and foreign credential IDs are both 404 so the two cannot be told apart.

A malformed credential ID is a 400 with InvalidCredentialId, not a 404. Base64Url validity is decidable offline, so it leaks nothing, and the handler never reaches a lookup, so 404 would be a claim it cannot back up.

GET does not sort. Neither EF store promises an order, and the tests match entries by credential ID rather than position so they cannot go flaky on it.

Rename is read, set name, upsert. A delete committing inside that window re-creates the row through the store's upsert. Passkey sign-in already does the same thing on every assertion to update the sign count, so the race predates this change and closing it needs a new method on the shipped IUserPasskeyStore<TUser>. I have left it and will file it separately.

Missing or expired ceremony state comes back as a 400. Taking too long between the two requests is a normal thing for a user to do, not a bug. A new internal PasskeyAuthenticationStateException marks that case; it derives from InvalidOperationException, so existing catch blocks are unaffected. Whether it should be public is an open question on the proposal.

A missing cookie scheme still throws, unlike expired state. It means the app was never configured for this, the same developer error as /login?useCookies=true on a bearer-only setup, and it already throws there.

The bearer and cookie selection in /login moved into a private helper that /passkeys/login shares. /login behaves exactly as before.

Template

The Blazor template's /Account/PasskeyRequestOptions had the same leak and gets the same one-line fix.

Deliberately not here

Deleting the last passkey is allowed even on an account with no password. That is an open question on the proposal, not an oversight.

The list response carries credential ID, name and creation time only. Transports and IsBackedUp would let a UI distinguish synced from device-bound credentials, but they are additive later.

The endpoints need the Identity.TwoFactorUserId cookie scheme to hold ceremony state between the two requests. AddIdentityApiEndpoints registers it, but an app wired for bearer tokens only cannot use passkeys.

Testing

MapIdentityApiTests drives all seven endpoints through a deterministic IPasskeyHandler rather than a real authenticator, covering authorization on every verb, bearer and both cookie modes, user mismatch, invalid and expired state, unknown emails, custom JSON naming, the exact set of fields on a listed passkey, rename and name clearing, delete, another user's credential, malformed IDs and unknown IDs. SignInManagerTest covers persistent and non-persistent sign-in, the metrics tags and the two ceremony-state failures.

The template's end-to-end test: virtual authenticator, register, log out, then log back in with the passkey.

Resolves #67301
Resolves #68199

@rolandVi rolandVi added the area-identity Includes: Identity and providers label Aug 4, 2026
@rolandVi
rolandVi requested a review from rokonec August 4, 2026 15:51
@rolandVi

rolandVi commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
4 pipeline(s) were filtered out due to trigger conditions.

@rolandVi
rolandVi requested a balanced review from Copilot August 12, 2026 07:48
@rolandVi
rolandVi changed the base branch from rolandVi/passkey-work to main August 26, 2026 09:19
@rolandVi
rolandVi requested review from a team and SamMonoRT as code owners August 26, 2026 09:19
@rolandVi

Copy link
Copy Markdown
Contributor Author

/azp run aspnetcore-ci

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@rolandVi
rolandVi merged commit 0978d71 into dotnet:main Sep 22, 2026
29 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-identity Includes: Identity and providers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Manage existing passkeys in MapIdentityApi() Update MapIdentityApi() to add endpoints for passkeys

2 participants