Cookie auth
Cookie sign-in for first-party web/browser clients. Pair with Identity management.
MapCookieAuthEndpoints (and the facade MapAuthEndpoints) maps LoginCookie to POST {prefix}/login. The scheme is always IdentityConstants.ApplicationScheme.
DI
builder.Services.AddAntiforgery();
builder.Services.AddCookieAuthEndpoints(); // ReAuth schemes + rate limits
The facade (AddAuthEndpoints) registers these for you.
Map
app.MapGroup("/identity").MapCookieAuthEndpoints<AppUser>();
The facade maps this group under IdentityPath (default /identity).
Routes
Relative to the group prefix (facade default /identity):
| Method | Path | Notes |
|---|---|---|
POST | /login | LoginCookie; application cookie; lockout on failure; rate-limited |
POST | /logout | Auth + CSRF |
GET | /csrfToken | Antiforgery token for unsafe methods |
Login query string
LoginCookie reads only useSessionCookies. useCookies is ignored.
| Query | Result |
|---|---|
| omitted | session application cookie |
useSessionCookies=true | session application cookie |
useSessionCookies=false | persistent application cookie |
useCookies=true | ignored |
Persistent cookie: POST /identity/login?useSessionCookies=false.
Passkey register/login uses a different flag table. See Passkeys.
Login body
Identity LoginRequest:
emailpasswordtwoFactorCode(optional)twoFactorRecoveryCode(optional)
CSRF
POST /login does not require antiforgery. POST /logout and cookie-authenticated unsafe methods (POST / PUT / PATCH / DELETE on CSRF-protected routes) do.
Client notes
- Send cookies:
credentials: "include"(or AxioswithCredentials: true). POST /logindoes not require CSRF.- Before logout and other CSRF-protected unsafe methods, call
GET /identity/csrfToken(or your prefix) and 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 web client origin differs from the API.
- Do not confuse
LoginCookiewith bearerLogin(MapBearerAuthEndpoints).