Skip to content

Support conditional passkey creation - #68194

Merged
rokonec merged 6 commits into
dotnet:mainfrom
rolandVi:passkeys/conditional-create
Sep 11, 2026
Merged

rokonec merged 6 commits into
dotnet:mainfrom
rolandVi:passkeys/conditional-create

Conversation

@rolandVi

@rolandVi rolandVi commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

API proposal tracked by #68192.

A Blazor Identity app can now create a passkey for someone silently, right after they sign in with a password, so they get moved off passwords without seeing a prompt or having to find a button. Today a passkey only appears if the user goes looking for the "add a passkey" page, which almost nobody does.

Example usage

if (SignInManager.SupportsPasskeyConditionalCreation)
{
    creationOptionsJson = await SignInManager.MakePasskeyCreationOptionsAsync(
        userEntity,
        isConditionallyMediated: true);
}

Why the server needs telling

This needs new public API because the server cannot work it out for itself. Mediation is not in clientDataJSON, so it cannot be inferred, and taking it from the client at attestation time would let anyone switch off the user-presence check. It is supplied when the options are made and rides along in the data-protected attestation state.

Design notes

Two checks get relaxed. The spec's registration steps skip the user-presence check when mediation is conditional, and the client is required to report both presence and verification as false. Separately, UserVerificationRequirement is downgraded from "required" to "preferred" in the generated options, because the browser refuses the ceremony outright if a conditional create asks for verification, so without that downgrade nothing reaches the server to verify.

I used a bool overload rather than an options object because an options object is source-breaking here: it makes existing new() { ... } call sites ambiguous. Details in the proposal.

SupportsConditionalCreation is there so an app with a custom IPasskeyHandler can ask before calling instead of getting an exception on every sign-in.

Template changes

The Blazor template sends the user through a short /Account/PasskeyUpgrade page after a completed sign-in, which does the creation and then continues to wherever they were headed. It is a separate page rather than something inline on the login page because navigating away cancels the login page's in-flight conditional get(), which the browser wants aborted before a conditional create starts.

The options are created in the sign-in handler itself, on the password, two-factor and recovery-code paths, and carried to the upgrade page in protected TempData. The upgrade page has no code that can issue options: reached without them, it redirects and does nothing. That keeps the decision to relax the registration checks with the code that just checked a credential, rather than with any request carrying a session cookie. It gives up after 5 seconds, and any failure is logged and swallowed, since the user never asked for this and should not see it fail.

Adding a passkey with only a session cookie is wider than this page. #66865 tracks the same weakness on the existing passkey management page and is not addressed here.

Testing

Unit tests cover the verification downgrade, the flag round-tripping through the attestation state, a conditional create succeeding with both flags false, an ordinary create still rejecting a missing user-presence flag, and the NotSupportedException from the default interface method.

The template E2E test stubs getClientCapabilities and intercepts navigator.credentials.create, recording the mediation it was called with. It checks a conditional create is attempted after a password sign-in, after two-factor and after a recovery code, that none is attempted at the two-factor prompt itself, and that navigating straight to /Account/PasskeyUpgrade with a session cookie attempts nothing. The interception means the E2E does not exercise attestation for a conditional create; the server side is covered by the unit tests

Resolves #67298.

@rolandVi
rolandVi requested a review from a team as a code owner August 4, 2026 09:21
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Aug 4, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @rolandVi. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@snemeckayova snemeckayova added area-identity Includes: Identity and providers and removed community-contribution Indicates that the PR has been added by a community member labels Aug 4, 2026
@rolandVi
rolandVi requested review from rokonec and removed request for a team August 4, 2026 15:51
@rolandVi
rolandVi requested a balanced review from Copilot August 12, 2026 07:47
@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 changed the base branch from rolandVi/passkey-work to main August 26, 2026 09:19
@rolandVi
rolandVi requested a review from SamMonoRT as a code owner August 26, 2026 09:19
@rokonec
rokonec merged commit 97e8487 into dotnet:main Sep 11, 2026
29 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 12, 2026
@ilonatommy

Copy link
Copy Markdown
Member

@rokonec it looks like this PR might have introduced some race into our templates, see the failures: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1610717&view=logs&j=6c33d704-163a-5170-38fa-caa7bc99f17c&t=a59c73d3-09b1-5a7e-4e53-9d83598ad56e

Also failing on:

Details Failing test:
BlazorTemplates.Tests.BlazorWebTemplateTest
    .BlazorWebTemplate_ConditionalPasskeyRegistration(
        browserKind: Chromium,
        persistenceOutcome: "Failure",
        signalOutcome: "Success")

Complete exception:

Microsoft.Playwright.PlaywrightException:
Protocol error (Network.getResponseBody): No resource with given identifier found

Response body is not available for a response that was navigated away from.
Read response.body() before triggering any navigation.

   at Microsoft.Playwright.Transport.Connection.InnerSendMessageToServerAsync[T](
       ChannelOwner object,
       String method,
       Dictionary`2 dictionary,
       Boolean keepNulls,
       Nullable`1 timeout)
       in /_/src/Playwright/Transport/Connection.cs:line 229

   at Microsoft.Playwright.Transport.Connection.WrapApiCallAsync[T](
       Func`1 action,
       Boolean isInternal,
       String title)
       in /_/src/Playwright/Transport/Connection.cs:line 535

   at Microsoft.Playwright.Core.Response.BodyAsync()
       in /_/src/Playwright/Core/Response.cs:line 79

   at Microsoft.Playwright.Core.Response.TextAsync()
       in /_/src/Playwright/Core/Response.cs:line 126

   at BlazorTemplates.Tests.BlazorWebTemplateTest
       .BlazorWebTemplate_ConditionalPasskeyRegistration(
           BrowserKind browserKind,
           String persistenceOutcome,
           String signalOutcome)
       in /_/src/ProjectTemplates/test/Templates.Blazor.Tests/BlazorWebTemplateTest.cs:line 266

   at BlazorTemplates.Tests.BlazorWebTemplateTest
       .BlazorWebTemplate_ConditionalPasskeyRegistration(
           BrowserKind browserKind,
           String persistenceOutcome,
           String signalOutcome)
       in /_/src/ProjectTemplates/test/Templates.Blazor.Tests/BlazorWebTemplateTest.cs:line 279

Relevant HTTP timeline:

[18.395s] Request starting:
POST /Account/PasskeyUpgrade
Content-Length: 1311

[18.482s] Request finished:
POST /Account/PasskeyUpgrade
Status: 200
Content-Type: text/html
Duration: 75.2956ms

[18.521s] Request starting:
POST /Account/PasskeyUpgrade
Content-Length: 24

[18.539s] Request finished:
POST /Account/PasskeyUpgrade
Status: 302
Duration: 5.3077ms

[18.539s] Request starting:
GET /auth?from=conditional-passkey&value=one%20two

[18.545s] Request finished:
GET /auth?from=conditional-passkey&value=one%20two
Status: 200
Content-Type: text/html
Duration: 5.4521ms

[19.129s] Request starting:
GET /test/passkeys

[19.150s] Request finished:
GET /test/passkeys
Status: 200
Content-Type: application/json
Duration: 21.2281ms

[19.349s] Test threw an exception:
Protocol error (Network.getResponseBody):
No resource with given identifier found

The first upgrade response returned 200 successfully. A second request then returned 302 and navigated to  /auth . After that navigation and the successful state-inspection request, line 266 attempted:

var redisplayedPage = await upgradeResponse.TextAsync();

Chromium had already discarded the first response body, causing the Playwright exception.

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

4 participants