white-keyboard-48926
06/02/2025, 7:40 PMbrief-egg-61061
06/02/2025, 7:40 PMbrief-egg-61061
06/02/2025, 7:41 PMreturn_to
parameter is populated and respected for proper redirection to the original URL in Ory Kratos, you need to: 1. Pass the return_to
parameter when initializing the flow: When you start a self-service flow (login, registration, settings, etc.), append the ?return_to=<your-original-url>
query parameter to the flow initialization endpoint. For example: /self-service/login/browser?return_to=<https://myapp.com/original-page>
This tells Kratos where to redirect the user after the flow completes successfully. 2. Whitelist the return URLs: For security, Ory Kratos requires you to whitelist allowed return URLs to prevent open redirect attacks. In your configuration, add the allowed domains: yaml selfservice: allowed_return_urls: - <https://myapp.com/>
This enables dynamic redirection to any path under <https://myapp.com/>
when using the return_to
parameter. 3. Ensure your UI and flow transitions preserve return_to
: The return_to
parameter does not automatically persist across different flows. If your application transitions from one flow to another (e.g., login to registration), you must extract the return_to
value from the current flow and pass it to the next flow. For example: js sdk.getLoginFlow({ id: flow }).then(({ data: flow }) => { const returnTo = flow.return_to return sdk.createBrowserRegistrationFlow({ id: flow.id, return_to: returnTo, }) })
This ensures the redirect URL is carried over between flows as needed. 4. Understand flow-specific behavior: - For most flows, the return_to
parameter is respected if set during initialization. - For recovery flows that transition into settings flows, the return_to
parameter is automatically carried over and used after the settings flow completes. - If you use AJAX/API clients, you must handle the redirection in your application logic, as browser redirects only occur for requests with Accept: text/html
headers. Note: If you do not set a return_to
parameter, Kratos will use the default redirect URL configured in your settings (e.g., selfservice.default_browser_return_url
or flow-specific overrides). For more details and examples, see the official documentation on [advanced redirects](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-advanced-integration) and [HTTP redirection configuration](https://www.ory.sh/docs/kratos/concepts/browser-redirect-flow-completion) in Ory Kratos. References: - [Advanced redirects](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-advanced-integration) - [HTTP redirection configuration](https://www.ory.sh/docs/kratos/concepts/browser-redirect-flow-completion)