<@U04UQ68083H> When I receive the recovery link on...
# ory-copilot
l
@chilly-king-10285 When I receive the recovery link on the email and I click on it, browser redirects to settings flow automatically. How is it getting done internally?
c
A message from kapa.ai
The process of redirecting to the settings flow after clicking on the recovery link is handled by Ory Kratos' recovery flow. Here's how it works: 1. A recovery flow is created with a
return_to
URL. This is done using the
/self-service/recovery/browser
or
/self-service/recovery/api
endpoints, depending on your application type.
Copy code
bash     curl -H 'Content-Type: application/json' \        -H 'Accept: application/json' \        -c cookies.txt \        "https://{project.slug}.<http://projects.oryapis.com/self-service/recovery/browser|projects.oryapis.com/self-service/recovery/browser>"
2. An email is sent to the user with a recovery link or code. This is part of the recovery flow's
link
or
code
methods. 3. The user completes the recovery flow by submitting the code or clicking the link. 4. After the recovery flow is completed, a session is issued and the user is redirected through the settings flow. This is where the user can update their password and profile information. 5. The user submits the settings flow with an updated password. 6. Finally, the user is redirected to the
return_to
URL, which was persisted across the flows. This process is managed by the Ory Kratos API, specifically the
updateRecoveryFlow
endpoint (
POST /self-service/recovery
). This endpoint behaves differently for API and browser flows and has several states, including
choose_method
,
sent_email
, and
passed_challenge
. The
passed_challenge
state is where the server responds with a HTTP 303 See Other redirect either to the Settings UI URL (if the link was valid) and instructs the user to update their password. Sources: - [Advanced redirects](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-advanced-integration#advanced-redirects) - [Recovery](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#recovery) - [Ory API Reference - updateRecoveryFlow](https://www.ory.sh/docs/reference/api)
l
@chilly-king-10285 after the completed recovery flow, how to get the issued session token/
c
A message from kapa.ai
After the recovery flow is completed, the issued session token can be retrieved from the response of the
updateRecoveryFlow
endpoint. The response includes a property
set_ory_session_token
which contains the session token. Here is an example of how the response might look:
Copy code
json {   "set_ory_session_token": {     "type": "string",     "x-go-enum-desc": "set_ory_session_token ContinueWithActionSetOrySessionTokenString"   },   "ory_session_token": {     "description": "Token is the token of the session",     "type": "string"   } }
In this response, the
ory_session_token
is the session token of the user. Please note that the actual implementation might vary based on your application setup and the specific Ory Kratos configuration. Source: [Ory API Reference - updateRecoveryFlow](https://www.ory.sh/docs/reference/api)
l
@chilly-king-10285 what is the updateRecoveryFlow endpoint
c
A message from kapa.ai
The
updateRecoveryFlow
endpoint is a part of Ory Kratos' API. It is used to update a recovery flow, which is a process that allows a user to recover their account. This endpoint behaves differently for API and browser flows and has several states. The endpoint is accessed via a
POST
request to
/self-service/recovery
. Here are the states of the recovery flow: - `choose_method`: This state expects
flow
(in the URL query) and
email
(in the body) to be sent and works with both API- and Browser-initiated flows. - `sent_email`: This is the success state after
choose_method
for the
link
method and allows the user to request another recovery email. It works for both API and Browser-initiated flows. - `passed_challenge`: This state expects a
token
to be sent in the URL query. Given the nature of the flow ("sending a recovery link"), it does not have any API capabilities. The server responds with a HTTP 303 See Other redirect either to the Settings UI URL (if the link was valid) and instructs the user to update their password, or a redirect to the Recover UI URL with a new Recovery Flow ID which contains an error message that the recovery link was invalid. For more information, you can refer to the [Ory Kratos Account Recovery Documentation](https://www.ory.sh/docs/self-service/flows/account-recovery). Source: [Ory API Reference - updateRecoveryFlow](https://www.ory.sh/docs/reference/api)
l
@chilly-king-10285 I dont want redirection after the recovery flow is completed, I just want the issued session token.
c
A message from kapa.ai
If you want to retrieve the issued session token after the recovery flow without redirection, you can do so by interacting with the Ory Kratos API directly. After the recovery flow is completed, a session token is issued. This token can be retrieved from the response of the
updateRecoveryFlow
endpoint. The response includes a property
set_ory_session_token
which contains the session token. Here is an example of how the response might look:
Copy code
json {   "set_ory_session_token": {     "type": "string",     "x-go-enum-desc": "set_ory_session_token ContinueWithActionSetOrySessionTokenString"   },   "ory_session_token": {     "description": "Token is the token of the session",     "type": "string"   } }
In this response, the
ory_session_token
is the session token of the user. Please note that the actual implementation might vary based on your application setup and the specific Ory Kratos configuration. Source: [Ory API Reference - updateRecoveryFlow](https://www.ory.sh/docs/reference/api)
l
@chilly-king-10285 how to request for this session token after the completed recovery flow
c
A message from kapa.ai
To request the session token after the recovery flow is completed, you would typically make a POST request to the
updateRecoveryFlow
endpoint of the Ory Kratos API. However, based on the provided extracts, the exact details or examples of how to make this request are not provided. In general, the request might look something like this:
Copy code
bash curl -X POST -H "Content-Type: application/json" \ -d '{"action": "set_ory_session_token"}' \ "<https://your-kratos-instance.com/self-service/recovery>"
Please replace
<http://your-kratos-instance.com|your-kratos-instance.com>
with your actual Ory Kratos instance URL. The response to this request should include the
ory_session_token
in the JSON response. Please note that this is a general example and the actual implementation might vary based on your application setup and the specific Ory Kratos configuration. For the exact details, you should refer to the Ory Kratos documentation or API reference.
l
@chilly-king-10285 after completing the recovery flow, I am getting the login browser flow.
c
A message from kapa.ai
After completing the recovery flow, if you're getting redirected to the login browser flow, it might be due to the configuration of your Ory Kratos setup. In the recovery flow, once a recovery flow is submitted successfully, a session is issued to the application. This allows the user to reset their password and update their profile information on the settings page. However, if you're getting redirected to the login flow instead, it might be due to the way your application handles the session token or the redirection URLs. Please check your Ory Kratos configuration and ensure that the session token is being handled correctly and the redirection URLs are set as expected. For more details, you can refer to the Ory Kratos documentation on [Recovery Flow](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#recovery) and [API Reference](https://www.ory.sh/docs/reference/api).
l
@chilly-king-10285 how to check that?
c
A message from kapa.ai
To check your Ory Kratos configuration and ensure that the session token is being handled correctly and the redirection URLs are set as expected, you can follow these steps: 1. Check your Ory Kratos configuration file: This file is usually named
kratos.yml
or
kratos.json
. In this file, look for the
selfservice
section and ensure that the
flows
and
methods
are configured correctly. 2. Check the session token handling in your application: After the recovery flow is completed, a session token is issued. Your application should handle this token correctly to maintain the user's session. The exact implementation will depend on your application's code. 3. Check the redirection URLs: In the Ory Kratos configuration file, check the
selfservice
section for
urls
. Ensure that the
default_return_to
URL is set to the correct location where you want users to be redirected after completing the recovery flow. 4. Check the recovery flow in your application: Ensure that your application correctly implements the recovery flow as described in the [Ory Kratos documentation](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#recovery). If you're still facing issues, it might be helpful to check the logs of your Ory Kratos instance for any error messages or warnings.
l
@chilly-king-10285 recovery: ui_url: http://localhost:4455/recovery enabled: true lifespan: 5m configure this
c
A message from kapa.ai
The configuration you've provided is for the recovery flow in Ory Kratos. Here's what each field means: - `ui_url`: This is the URL of the User Interface or page where the recovery flow will start. In your case, it's set to
<http://localhost:4455/recovery>
. - `enabled`: This field indicates whether the recovery flow is enabled or not. In your case, it's set to
true
, which means the recovery flow is enabled. - `lifespan`: This field defines how much time the user has to complete the recovery flow in the UI. In your case, it's set to
5m
(5 minutes). To configure these settings, you need to update your Ory Kratos configuration file (usually named
kratos.yml
or
kratos.json
). Here's how you can do it: 1. Open your Ory Kratos configuration file in a text editor. 2. Find the
selfservice
section in the file. 3. Under
selfservice
, find the
flows
section. 4. Under
flows
, find the
recovery
section. 5. Update the
ui_url
,
enabled
, and
lifespan
fields as needed. Here's an example of how it might look:
Copy code
yaml selfservice:   flows:     recovery:       ui_url: <http://localhost:4455/recovery>       enabled: true       lifespan: 5m
After updating the configuration, save the file and restart your Ory Kratos instance for the changes to take effect. Please note that the actual steps might vary based on your specific setup and configuration. Sources: - [Ory Kratos Self-service Flows: Account Recovery and Password Reset](https://www.ory.sh/docs/kratos/self-service/flows/account-recovery-password-reset#configuration) - [Ory Kratos Configuration Reference](https://www.ory.sh/docs/kratos/reference/configuration)
l
@chilly-king-10285 I said to configure this settings to get the session token after successful recovery completion instead of redirecting to the login browser flow?
c
A message from kapa.ai
Based on the provided extracts, there isn't a direct configuration setting in Ory Kratos to get the session token after successful recovery completion instead of redirecting to the login browser flow. However, you can handle this programmatically in your application. After the recovery flow is completed, a session token is issued. This token can be retrieved from the response of the
updateRecoveryFlow
endpoint. The response includes a property
set_ory_session_token
which contains the session token. Here is an example of how the response might look:
Copy code
json {{   "set_ory_session_token": {{     "type": "string",     "x-go-enum-desc": "set_ory_session_token ContinueWithActionSetOrySessionTokenString"   }},   "ory_session_token": {{     "description": "Token is the token of the session",     "type": "string"   }} }}
In this response, the
ory_session_token
is the session token of the user. Please note that the actual implementation might vary based on your application setup and the specific Ory Kratos configuration. Source: [Ory API Reference - updateRecoveryFlow](https://www.ory.sh/docs/reference/api)