|
| 1 | +# Passkey-First Identity in ASP.NET Core — Minimal .NET 10 Sample |
| 2 | + |
| 3 | +Full tutorial: [Passkeys in ASP.NET Core Identity (.NET 10): Build a Passwordless-First Web App with WebAuthn](https://www.dotnet-guide.com/tutorials/aspnet-core/passkey-first-identity/) |
| 4 | + |
| 5 | +## What this sample demonstrates |
| 6 | + |
| 7 | +- .NET 10 ASP.NET Core Identity with schema version 3 |
| 8 | +- SQLite database with `EnsureCreated` schema bootstrapping |
| 9 | +- Development-only bootstrap password login |
| 10 | +- Passkey creation options via `SignInManager.MakePasskeyCreationOptionsAsync` |
| 11 | +- Browser WebAuthn `navigator.credentials.create()` with native JSON serialization |
| 12 | +- Attestation verification via `SignInManager.PerformPasskeyAttestationAsync` |
| 13 | +- Stored passkey persistence via `UserManager.AddOrUpdatePasskeyAsync` |
| 14 | +- Username-first passkey request options via `SignInManager.MakePasskeyRequestOptionsAsync` |
| 15 | +- Passkey sign-in via `SignInManager.PasskeySignInAsync` |
| 16 | +- Passkey listing via `UserManager.GetPasskeysAsync` |
| 17 | +- Antiforgery validation on every state-changing passkey endpoint |
| 18 | +- Server-side integration tests using `WebApplicationFactory` |
| 19 | + |
| 20 | +## Architecture diagram |
| 21 | + |
| 22 | +``` |
| 23 | +Bootstrap login |
| 24 | + │ |
| 25 | + ▼ |
| 26 | +Identity cookie |
| 27 | + │ |
| 28 | + ├── creation options |
| 29 | + ├── browser authenticator |
| 30 | + └── verified passkey storage |
| 31 | +
|
| 32 | +Later sign-in |
| 33 | + │ |
| 34 | + ├── request options |
| 35 | + ├── signed assertion |
| 36 | + └── Identity cookie |
| 37 | +``` |
| 38 | + |
| 39 | +## File structure |
| 40 | + |
| 41 | +``` |
| 42 | +aspnet-core/ |
| 43 | +└── passkey-first-identity/ |
| 44 | + ├── PasskeyIdentityMinimal.slnx |
| 45 | + ├── README.md |
| 46 | + ├── src/ |
| 47 | + │ └── PasskeyIdentityMinimal/ |
| 48 | + │ ├── PasskeyIdentityMinimal.csproj |
| 49 | + │ ├── Program.cs |
| 50 | + │ ├── appsettings.json |
| 51 | + │ ├── Data/ |
| 52 | + │ │ ├── ApplicationDbContext.cs |
| 53 | + │ │ └── ApplicationUser.cs |
| 54 | + │ ├── Endpoints/ |
| 55 | + │ │ ├── AntiforgeryEndpointExtensions.cs |
| 56 | + │ │ └── PasskeyEndpoints.cs |
| 57 | + │ └── wwwroot/ |
| 58 | + │ ├── index.html |
| 59 | + │ └── passkeys.js |
| 60 | + └── tests/ |
| 61 | + └── PasskeyIdentityMinimal.Tests/ |
| 62 | + ├── PasskeyIdentityMinimal.Tests.csproj |
| 63 | + ├── PasskeyEndpointTests.cs |
| 64 | + └── PasskeyIdentityFactory.cs |
| 65 | +``` |
| 66 | + |
| 67 | +## Prerequisites |
| 68 | + |
| 69 | +- [.NET 10 SDK](https://dotnet.microsoft.com/download/dotnet/10.0) |
| 70 | +- A browser that supports WebAuthn (Chrome, Edge, Firefox, Safari) |
| 71 | +- HTTPS is required for WebAuthn in production; localhost is exempt |
| 72 | + |
| 73 | +## Run instructions |
| 74 | + |
| 75 | +```powershell |
| 76 | +cd aspnet-core\passkey-first-identity |
| 77 | +dotnet restore |
| 78 | +dotnet build --configuration Release --no-restore |
| 79 | +dotnet test --configuration Release --no-build |
| 80 | +dotnet run --project src\PasskeyIdentityMinimal --configuration Release --no-build |
| 81 | +``` |
| 82 | + |
| 83 | +On Linux/macOS: |
| 84 | + |
| 85 | +```bash |
| 86 | +cd aspnet-core/passkey-first-identity |
| 87 | +ASPNETCORE_ENVIRONMENT=Development dotnet run --project src/PasskeyIdentityMinimal --configuration Release --no-build |
| 88 | +``` |
| 89 | + |
| 90 | +The application starts on `https://localhost:5001` and `http://localhost:5000`. |
| 91 | + |
| 92 | +## Development credentials |
| 93 | + |
| 94 | +| Field | Value | |
| 95 | +|----------|------------------| |
| 96 | +| Email | demo@example.com | |
| 97 | +| Password | DemoPass123! | |
| 98 | + |
| 99 | +**These are development-only credentials.** The bootstrap user exists only in Development and Testing environments. The password exists only to enroll the first passkey. Do not use these credentials in production. |
| 100 | + |
| 101 | +## Manual browser test |
| 102 | + |
| 103 | +1. Trust the development certificate: |
| 104 | + ```bash |
| 105 | + dotnet dev-certs https --trust |
| 106 | + ``` |
| 107 | + |
| 108 | +2. Start the application in the `Development` environment: |
| 109 | + ```bash |
| 110 | + ASPNETCORE_ENVIRONMENT=Development dotnet run --project src/PasskeyIdentityMinimal |
| 111 | + ``` |
| 112 | + |
| 113 | +3. Open `https://localhost:5001` in your browser. |
| 114 | + |
| 115 | +4. Click **Sign in with password** (the credentials are pre-filled). |
| 116 | + |
| 117 | +5. After a successful sign-in, click **Create passkey**. |
| 118 | + |
| 119 | +6. Complete the authenticator prompt (Windows Hello, Touch ID, browser virtual authenticator, or another supported authenticator). |
| 120 | + |
| 121 | +7. Click **List my passkeys** to confirm the passkey appears. |
| 122 | + |
| 123 | +8. Click **Sign out**. |
| 124 | + |
| 125 | +9. Enter `demo@example.com` and click **Sign in with passkey**. |
| 126 | + |
| 127 | +10. Complete the authenticator prompt. |
| 128 | + |
| 129 | +11. Confirm the application shows the authenticated state. |
| 130 | + |
| 131 | +### Using a browser virtual authenticator (Chrome) |
| 132 | + |
| 133 | +1. Open Chrome DevTools (`F12`). |
| 134 | +2. Click **More tools** → **WebAuthn**. |
| 135 | +3. Check **Enable virtual authenticator environment**. |
| 136 | +4. Click **Add** to create a resident-key-capable authenticator. |
| 137 | +5. Complete the passkey registration and sign-in flows described above. |
| 138 | + |
| 139 | +## Important boundary |
| 140 | + |
| 141 | +This sample is deliberately smaller than the full tutorial. It focuses on: |
| 142 | + |
| 143 | +- Bootstrap login |
| 144 | +- Passkey enrollment |
| 145 | +- Username-first passkey sign-in |
| 146 | +- Passkey listing |
| 147 | +- Schema and antiforgery correctness |
| 148 | + |
| 149 | +It deliberately omits: |
| 150 | + |
| 151 | +- Conditional UI and username-field autofill |
| 152 | +- Username-less (discovery) sign-in |
| 153 | +- Passkey rename and deletion |
| 154 | +- Final-factor deletion protection |
| 155 | +- Password removal |
| 156 | +- Verified-email recovery |
| 157 | +- Recovery codes |
| 158 | +- Email sending |
| 159 | +- Attestation-statement policy validation |
| 160 | +- Authenticator-model allow or deny lists (AAGUID) |
| 161 | +- FIDO Metadata Service integration |
| 162 | +- FIDO2 net library |
| 163 | +- Organization-managed security keys |
| 164 | +- IdentityServer integration |
| 165 | +- Selenium, Playwright, or browser automation |
| 166 | +- Virtual authenticator orchestration in CI |
| 167 | +- MVC or Razor Pages port |
| 168 | +- Production reverse-proxy setup |
| 169 | +- Distributed rate limiting |
| 170 | + |
| 171 | +These topics remain in the full tutorial. |
| 172 | + |
| 173 | +## Passkey enrollment is not a complete recovery strategy |
| 174 | + |
| 175 | +Losing the only authenticator can permanently lock the user out. Production applications should: |
| 176 | + |
| 177 | +- Encourage users to register at least two passkeys. |
| 178 | +- Provide verified email, recovery codes, or another approved factor. |
| 179 | +- Protect deletion of the final factor with additional checks. |
| 180 | +- Plan for account recovery before users need it. |
| 181 | + |
| 182 | +This lightweight sample does not implement passkey deletion, password removal, or account recovery. |
| 183 | + |
| 184 | +## Built-in attestation-policy limits |
| 185 | + |
| 186 | +ASP.NET Core Identity passkeys are not a complete general-purpose WebAuthn governance stack. This sample does not provide: |
| 187 | + |
| 188 | +- Attestation-statement policy |
| 189 | +- Authenticator-model allow or deny lists |
| 190 | +- FIDO Metadata Service checks |
| 191 | +- Enterprise hardware-key governance |
| 192 | + |
| 193 | +Readers needing those capabilities should use the full tutorial's guidance and assess a full WebAuthn library. |
| 194 | + |
| 195 | +## Verification details |
| 196 | + |
| 197 | +| Item | Value | |
| 198 | +|--------------------|--------------------------------------------------------------| |
| 199 | +| Target framework | `net10.0` | |
| 200 | +| Package | Version | |
| 201 | +| `Microsoft.AspNetCore.Identity.EntityFrameworkCore` | `10.0.10` | |
| 202 | +| `Microsoft.EntityFrameworkCore.Sqlite` | `10.0.10` | |
| 203 | +| `Microsoft.EntityFrameworkCore.Design` | `10.0.10` | |
| 204 | +| `Microsoft.AspNetCore.Mvc.Testing` | `10.0.10` | |
| 205 | +| `Microsoft.NET.Test.Sdk` | `17.14.1` | |
| 206 | +| `xunit.v3` | `3.2.2` | |
| 207 | +| `xunit.runner.visualstudio` | `3.1.5` | |
| 208 | +| Database | Temporary SQLite file (`PasskeyIdentityMinimal.db` in the project directory during development; in-memory SQLite during testing) | |
| 209 | +| RP ID | `localhost` (development only; change for production) | |
| 210 | +| External services | None | |
| 211 | +| Containers | None | |
| 212 | +| API keys | None | |
| 213 | +| Hardware authenticator | Optional for manual testing | |
| 214 | +| Browser virtual authenticator | Supported for manual testing (Chrome DevTools) | |
| 215 | +| Last reviewed | 2026-07-30 | |
| 216 | +| Release build | Verified | |
| 217 | +| Tests | Verified (6/6 passing) | |
| 218 | +| Browser ceremony | Requires a WebAuthn-capable browser and authenticator; not verified on this headless build server | |
| 219 | + |
| 220 | +## License |
| 221 | + |
| 222 | +Sample code in this repository is available under the [MIT License](../../LICENSE). |
0 commit comments