<@U04UQ68083H> in ory kratos self hosting, what do...
# ory-copilot
a
@chilly-king-10285 in ory kratos self hosting, what does the config file look like if we want to enable code recovery?
b
A message from kapa.ai
To enable code recovery in a self-hosted Ory Kratos environment, you need to modify the configuration file. Here's what the relevant part of the config file should look like:
Copy code
yaml selfservice:   methods:     code:       enabled: true       config:         lifespan: 15m      flows:     recovery:       enabled: true       lifespan: 15m       use: code       notify_unknown_recipients: false
This configuration enables the code recovery method, sets the lifespan for the recovery code to 15 minutes, and configures the recovery flow to use the code method. Here's a breakdown of the key settings: 1.
selfservice.methods.code.enabled: true
enables the code method for recovery. 2.
selfservice.flows.recovery.enabled: true
enables the recovery flow. 3.
selfservice.flows.recovery.use: code
specifies that the code method should be used for recovery. You can adjust the
lifespan
values according to your needs. The
notify_unknown_recipients
option is set to
false
by default, but you can enable it if you want to send notifications to unregistered addresses. Remember to update your Ory Kratos configuration file with these settings to enable code recovery in your self-hosted environment. [Source: Kratos Documentation - Account recovery and password reset](https://www.ory.sh/docs/kratos/self-service/flows/account-recovery-password-reset#configuration)
a
@chilly-king-10285 how do I configure the url that I get redirected to after completing code recovery?
b
A message from kapa.ai
To configure the URL you get redirected to after completing code recovery in Ory Kratos, you need to modify the configuration file. Here's how you can set up the redirect URL: 1. For a default redirect URL that applies to all flows:
Copy code
yaml selfservice:   default_browser_return_url: <https://your-default-redirect-url.com/>
2. For a specific redirect URL after the recovery flow:
Copy code
yaml selfservice:   flows:     recovery:       after:         default_browser_return_url: <https://your-recovery-specific-redirect-url.com/>
3. If you want to set a redirect URL specifically for the code method:
Copy code
yaml selfservice:   flows:     recovery:       after:         code:           default_browser_return_url: <https://your-code-recovery-specific-redirect-url.com/>
These configurations allow you to specify where the user should be redirected after successfully completing the code recovery process. Additionally, if you want to use dynamic return URLs, you can whitelist allowed domains:
Copy code
yaml selfservice:   allowed_return_urls:     - <https://www.your-app-domain.com/>
This allows you to use the
?return_to=
query parameter when initializing the recovery flow, enabling more flexible redirects while preventing open redirect attacks. Remember to update your Ory Kratos configuration file with these settings to configure the post-recovery redirect URL in your self-hosted environment. [Source: HTTP redirection configuration](https://www.ory.sh/docs/kratos/concepts/browser-redirect-flow-completion#redirection)
a
@chilly-king-10285 I tried this:
Copy code
selfservice:
  flows:
    recovery:
      after:
        default_browser_return_url: <https://your-recovery-specific-redirect-url.com/>
b
A message from kapa.ai
I apologize, but it seems there might be an issue with the configuration you've tried. Let me provide you with the correct format and some additional information: The configuration you've attempted is close, but there's a small formatting error. Here's the correct way to set up the post-recovery redirect URL:
Copy code
yaml selfservice:   flows:     recovery:       after:         default_browser_return_url: <https://your-recovery-specific-redirect-url.com/>
Note that the URL should not be enclosed in angle brackets (
<>
). Here are a few important points to keep in mind: 1. Make sure this configuration is part of your Ory Kratos configuration file (often named
kratos.yml
or similar). 2. The URL you specify should be a valid, fully-qualified URL that points to the page you want users to see after completing the recovery process. 3. If you're using this in a production environment, ensure that the URL uses HTTPS for security. 4. After making changes to the configuration file, you'll need to restart your Ory Kratos instance for the changes to take effect. If you're still experiencing issues after making this correction, it might be helpful to check the rest of your configuration and ensure there are no conflicting settings. Also, verify that your Ory Kratos instance is picking up the updated configuration file. [Source: HTTP redirection configuration](https://www.ory.sh/docs/kratos/concepts/browser-redirect-flow-completion#redirection)
a
@chilly-king-10285 in ory kratos self hosting, how to require MFA for recovery flow?
b
A message from kapa.ai
To require Multi-Factor Authentication (MFA) for the recovery flow in a self-hosted Ory Kratos environment, you need to modify the configuration file. Here's how you can set it up:
Copy code
yaml selfservice:   flows:     settings:       required_aal: highest_available
This configuration forces users to provide the highest authentication factor available to access their account settings, which includes the recovery flow. Here's what this means: 1. Users without a second factor configured can access the settings after they sign in with their password. 2. Users that have a second factor set up (such as TOTP or WebAuthn) will be required to complete the second factor challenge to access account settings and perform recovery. If you want to enforce MFA for all users that have configured a second factor, not just for account settings but for using your app in general, you can also add this configuration:
Copy code
yaml session:   whoami:     required_aal: highest_available
Remember to update your Ory Kratos configuration file with these settings and restart your Kratos instance for the changes to take effect. [Source: Kratos Documentation - Configure multi-factor authentication](https://www.ory.sh/docs/kratos/self-hosted/mfa#enforce-mfa) [Source: Kratos Documentation - Require multi-factor for account recovery](https://www.ory.sh/docs/kratos/self-service/flows/account-recovery-password-reset#require-multi-factor-for-account-recovery)