Enable account recovery through email codes and magic links
The recovery flow allows users to regain access to their accounts when they’ve lost their credentials. Kratos supports email-based and code-based recovery strategies.
For native applications (mobile, desktop, server-to-server):
curl -X GET \ 'https://{project}.projects.oryapis.com/self-service/recovery/api' \ -H 'Accept: application/json'
Recovery can be disabled in the configuration. If disabled, this endpoint returns a 400 error with message “Recovery is not allowed because it was disabled.”
Recovery flows are only available for unauthenticated users. Authenticated users receive a 400 error.
Status: 400 Bad RequestThe user is already authenticated. Recovery is only available for unauthenticated users.Solution: User should logout first or use the settings flow to change credentials.
Status: 410 GoneThe recovery flow has expired.Solution: Initialize a new flow.Browser flows include a redirect_to URL in the error response.
Status: 400 Bad RequestRecovery has been disabled in the configuration.Solution: Enable recovery in the Kratos configuration.
Status: 403 ForbiddenCSRF token validation failed.Solution: Ensure cookies are properly forwarded in browser flows.
# 1. Initialize the flowcurl -X GET 'https://{project}.projects.oryapis.com/self-service/recovery/browser'# Browser is redirected to UI with flow ID# User visits: https://your-app.com/recovery?flow=<flow_id># 2. Request recovery codecurl -X POST \ 'https://{project}.projects.oryapis.com/self-service/recovery?flow=<flow_id>' \ -H 'Content-Type: application/x-www-form-urlencoded' \ -d 'method=code&[email protected]&csrf_token=...'# 3. Submit code from emailcurl -X POST \ 'https://{project}.projects.oryapis.com/self-service/recovery?flow=<flow_id>' \ -H 'Content-Type: application/x-www-form-urlencoded' \ -d 'method=code&code=123456&csrf_token=...'# User is redirected to settings flow to update password