Browser vs API flows
Ory Kratos supports two distinct flow types optimized for different client environments:Browser flows
Browser flows are designed for web applications that run in a browser environment. These flows:- Use HTTP cookies for session management
- Implement CSRF protection via anti-CSRF tokens and cookies
- Redirect users to configured UI URLs (e.g.,
/login,/registration) - Set
Content-Type: application/x-www-form-urlencodedorapplication/json - Return HTTP 303 redirects on success or validation errors
GET /self-service/login/browserGET /self-service/registration/browserGET /self-service/recovery/browser
API flows (native apps)
API flows are designed for native applications without browser access, such as mobile apps, smart TVs, or CLI tools. These flows:- Use session tokens instead of cookies
- Do not require CSRF protection
- Return JSON responses directly without redirects
- Accept session tokens via
X-Session-Tokenheader - Expect
Content-Type: application/json
GET /self-service/login/apiGET /self-service/registration/apiGET /self-service/recovery/api
Flow lifecycle
All self-service flows follow a consistent lifecycle:- Initialization - Create a new flow by calling the appropriate endpoint
- UI rendering - Display the flow’s UI nodes to the user
- Submission - User submits form data to complete the flow
- Validation - Kratos validates the submission and returns success or errors
- Completion - On success, create session (login/registration) or update state
Flow states
Flows contain astate field indicating their current status:
choose_method- User needs to select an authentication methodsent_email- Verification or recovery email has been sentpassed_challenge- User successfully completed a challengesuccess- Flow completed successfully
Flow expiration
All flows have a configurable expiration time (typically 1 hour). After expiration:- Accessing the flow returns HTTP 410 Gone
- Users must initialize a new flow to continue
- The response includes
use_flow_idto reference the replacement flow
Authentication methods
Kratos supports multiple authentication methods:- Password - Traditional username/password authentication
- OIDC - Social sign-in with Google, GitHub, etc.
- WebAuthn - Passwordless authentication with biometrics or security keys
- Code - One-time codes sent via email or SMS
- TOTP - Time-based one-time passwords (2FA)
- Lookup secrets - Recovery codes for 2FA
Cookie vs token authentication
Cookie-based sessions (browser flows)
Browser flows use HTTP-only cookies for session management:Token-based sessions (API flows)
API flows use session tokens passed in theX-Session-Token header:
CSRF tokens
Browser flows require CSRF protection. Each flow includes acsrf_token field that must be submitted with form data:
- Are unique per flow
- Expire with the flow
- Must be included in all browser flow submissions
- Are not required for API flows
Error handling
Common error codes across self-service flows:| Status | Error ID | Description |
|---|---|---|
| 400 | session_already_available | User is already authenticated |
| 400 | browser_location_change_required | Browser needs to navigate to a different URL |
| 403 | security_csrf_violation | CSRF token validation failed |
| 410 | self_service_flow_expired | Flow has expired, create a new one |
| 422 | security_identity_mismatch | The return_to URL is not allowed |
Next steps
Login flow
Authenticate users with password, social sign-in, or passwordless methods
Registration flow
Create new identity accounts with customizable traits
Recovery flow
Enable account recovery via email or other channels
Verification flow
Verify email addresses and phone numbers