square-napkin-92357
06/09/2025, 2:42 AMself-service/login/browser?aal=aal2
, but someone need to totp via email, someone don not need, how can i do this?brief-egg-61061
06/09/2025, 2:42 AMbrief-egg-61061
06/09/2025, 2:42 AM/self-service/login/browser?aal=aal2
, it means Ory Kratos is enforcing step-up authentication (AAL2), typically requiring a second factor like TOTP or code via email/SMS. Whether a user is prompted for TOTP, email, or not prompted at all depends on: 1. MFA Configuration: If you have enabled multiple MFA methods (TOTP, code via email/SMS), users will be prompted to use the second factor they have configured. If a user has not set up any second factor, they may not be able to proceed, or the flow may allow fallback to another method if configured. 2. User Enrollment: Each user must enroll in their preferred MFA method (e.g., pairing a TOTP app or registering an email/phone for code delivery). Ory does not automatically enroll users in TOTP; they must set it up in their account settings first. If a user has not set up TOTP but has code via email/SMS enabled, they will be prompted for that instead. If neither is set up, the flow may block them or allow access based on your enforcement settings. 3. Enforcement Model: The behavior is controlled by your configuration: - required_aal: highest_available
(strict): Users with a second factor configured must use it; those without can proceed with just password (AAL1). - `required_aal: aal2`: All users must complete a second factor, regardless of whether they have one set up. In Ory Network, the default is strict (highest_available
), so only users who have set up a second factor are required to use it. Others can log in with just their password. You can adjust this in the Ory Console or your config file under selfservice.flows.settings.required_aal
and `session.whoami.required_aal`[Step-up authentication](https://www.ory.sh/docs/kratos/mfa/step-up-authentication). Summary of what you can do: - If you want only users who have set up MFA to be prompted for AAL2, use highest_available
. - If you want all users to be forced to use MFA, use aal2
. - Make sure users have actually enrolled in their preferred MFA method (TOTP, email, SMS) in their account settings. - If you want to allow fallback to email/SMS code for those who haven't set up TOTP, enable those methods in your config. References: - [Step-up authentication](https://www.ory.sh/docs/kratos/mfa/step-up-authentication) - [Configure multi-factor authentication](https://www.ory.sh/docs/kratos/self-hosted/mfa) - [TOTP setup and user enrollment](https://www.ory.sh/docs/kratos/mfa/totp) - [MFA via SMS and email](https://www.ory.sh/docs/kratos/mfa/mfa-via-sms) If you need more granular control (e.g., force TOTP for some users and email for others), you would need to manage user enrollment and possibly customize your flows/UI to guide users to set up the desired second factor.square-napkin-92357
06/09/2025, 6:04 AMbrief-egg-61061
06/09/2025, 6:04 AMbrief-egg-61061
06/09/2025, 6:04 AMsquare-napkin-92357
06/09/2025, 6:32 AMbrief-egg-61061
06/09/2025, 6:32 AMbrief-egg-61061
06/09/2025, 6:32 AM/self-service/recovery
endpoint with the user's email and specify the method as code
. For browser flows, include the CSRF token and cookies as required. Example cURL command for a browser flow: bash curl -X POST -H 'Content-Type: application/json' \ -H 'Accept: application/json' \ -d '{"method":"code","email":"<mailto:email@example.com|email@example.com>","csrf_token":"your-csrf-token"}' \ -b cookies.txt \ "https://$<http://PROJECT_SLUG.projects.oryapis.com/self-service/recovery?flow=<your-flow-id|PROJECT_SLUG.projects.oryapis.com/self-service/recovery?flow=<your-flow-id>>"
This will send a recovery code to the specified email address if it is registered. The user will then receive an email with the code to continue the recovery process. If you want to trigger this in a native (non-browser) flow, you can omit the CSRF token and cookies as appropriate for your setup [Submit recovery flow](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#submit-recovery-flow). 2. Configuration: Make sure your recovery method is set to code
in your Ory Kratos configuration. This ensures that a one-time code is sent via email for account recovery [Account recovery](https://www.ory.sh/docs/identities/get-started/account-recovery). 3. API Request Body: The request body should include: - `method`: set to "code"
- `email`: the user's email address - `csrf_token`: required for browser flows For more details on the request body, see the [API reference](https://www.ory.sh/docs/kratos/reference/api). Note: If you include the email
field again after a code has already been sent, it will invalidate the previous code and send a new one [API reference](https://www.ory.sh/docs/kratos/reference/api). --- Summary: To trigger sending a code via email for account recovery, POST to /self-service/recovery
with {"method":"code","email":"<mailto:user@example.com|user@example.com>"}
and handle the flow as described above.square-napkin-92357
06/09/2025, 6:35 AMbrief-egg-61061
06/09/2025, 6:35 AMbrief-egg-61061
06/09/2025, 6:35 AM/self-service/verification
endpoint with the following JSON body: json { "method": "code", "email": "<mailto:user@example.com|user@example.com>", "csrf_token": "your-csrf-token" // required for browser flows }
Example cURL for a browser flow: bash curl -X POST \ -H 'Content-Type: application/json' \ -H 'Accept: application/json' \ -b cookies.txt \ -d '{"method":"code","email":"<mailto:user@example.com|user@example.com>","csrf_token":"your-csrf-token"}' \ "https://$<http://PROJECT_SLUG.projects.oryapis.com/self-service/verification?flow=<your-flow-id|PROJECT_SLUG.projects.oryapis.com/self-service/verification?flow=<your-flow-id>>"
This will send a verification code to the specified email address if it is registered and verifiable. The user will then receive an email with the code to complete the verification process [Submit verification flow](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#submit-verification-flow). Note: - The method
must be set to "code"
to trigger sending a code via email. - For browser flows, you must include the CSRF token and cookies. - If you submit the email again after a code has already been sent, it will invalidate the previous code and send a new one [API reference](https://www.ory.sh/docs/kratos/reference/api). For more details, see the [Ory Kratos documentation on verification flows](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#submit-verification-flow).