Modules
Cookie auth
Identity cookie login, logout, and CSRF token endpoints for SPA hosts.
Cookie sign-in for first-party SPAs. Pair with Identity management.
DI
builder.Services.AddAntiforgery();
builder.Services.AddCookieAuthEndpoints(); // ReAuth schemes + rate limits
Map
app.MapGroup("/identity").MapCookieAuthEndpoints<AppUser>();
Routes
Relative to the group prefix (facade default /identity):
| Method | Path | Notes |
|---|---|---|
POST | /login | Application cookie; lockout on failure; rate-limited |
POST | /logout | Auth + CSRF |
GET | /csrfToken | Antiforgery token for unsafe methods |
Login body
Uses Identity login fields, including optional:
twoFactorCodetwoFactorRecoveryCode
SPA client notes
- Send cookies:
credentials: "include"(or AxioswithCredentials: true). GET /identity/csrfToken(or your prefix).- On
POST/PUT/PATCH/DELETE, send headerRequestVerificationTokenwith the token value.
Gotchas
- Pipeline must include authentication, authorization, rate limiting, and antiforgery.
- Do not map cookie and bearer login on the same path without separate groups — pick one sign-in stack per prefix.
- CORS must allow credentials if the SPA origin differs from the API.