few-oyster-74399
01/15/2025, 4:00 PMbrief-egg-61061
01/15/2025, 4:00 PMbrief-egg-61061
01/15/2025, 4:01 PMaal2
. 3. Trigger dynamic MFA: For specific users or sensitive functions, you can trigger dynamic MFA by initiating a new login flow with the aal
parameter set to aal2
. Here's an example of how to trigger dynamic MFA: /self-service/login/browser?aal=aal2 /self-service/login/api?aal=aal2
If you want to refresh the session using the second factor: /self-service/login/browser?refresh=true&aal=aal2 /self-service/login/api?refresh=true&aal=aal2
When the user successfully provides their configured second factor: - The method (e.g., TOTP) is added to the Ory Session. - The Ory Session Authenticator Assurance Level (AAL) is set to aal2
. - The authenticated_at
time is updated to the time when the user provides the second factor. By implementing this approach, you can enforce 2FA for specific users or operations in your application, providing an additional layer of security where needed. For more detailed information on step-up authentication and configuring MFA, you can refer to the [Step-up authentication documentation](https://www.ory.sh/docs/kratos/mfa/step-up-authentication).few-oyster-74399
01/15/2025, 4:02 PMbrief-egg-61061
01/15/2025, 4:02 PMbrief-egg-61061
01/15/2025, 4:02 PMyaml selfservice: flows: registration: before: hooks: - hook: web_hook config: url: <https://your-webhook-url.com/check-email-domain> method: POST
In your webhook, you would implement the logic to check the email domain. If the email doesn't end with the required domain, you would return an error response to prevent the registration from proceeding. Unfortunately, the provided knowledge sources don't contain a specific example of how to implement this exact functionality. However, this approach aligns with Ory's extensibility mechanisms described in the [Hooks documentation](https://www.ory.sh/docs/kratos/hooks/configure-hooks). For a more detailed guide on implementing custom actions and integrating them with Ory, I recommend referring to the official Ory documentation or reaching out to Ory support for specific implementation details.few-oyster-74399
01/15/2025, 4:08 PMbrief-egg-61061
01/15/2025, 4:08 PMbrief-egg-61061
01/15/2025, 4:08 PMtraits.email
field of each identity. 2. Create a login hook: Implement a webhook that checks the user's email domain during the login process. You can configure this in your Ory Identities settings: yaml selfservice: flows: login: before: hooks: - hook: web_hook config: url: <https://your-webhook-url.com/check-email-domain> method: POST
In your webhook, implement logic to check the email domain and return an error if it doesn't match your requirements. 3. Update or deactivate non-compliant accounts: For users with non-compliant email domains, you can either update their email addresses (if appropriate) or deactivate their accounts using the Identity Management API. It's important to note that this approach may impact existing users, so you should plan carefully and communicate any changes to your user base. For more information on implementing webhooks and managing identities, you can refer to the following Ory documentation: - [Integrate with Ory Cloud through webhooks](https://www.ory.sh/docs/guides/integrate-with-ory-cloud-through-webhooks#modify-identities) - [Hooks documentation](https://www.ory.sh/docs/kratos/hooks/configure-hooks) Remember to test thoroughly in a non-production environment before applying these changes to your live system.few-oyster-74399
01/15/2025, 4:14 PMbrief-egg-61061
01/15/2025, 4:14 PMbrief-egg-61061
01/15/2025, 4:15 PMyaml selfservice: flows: registration: before: hooks: - hook: web_hook config: url: <https://your-webhook-url.com/check-user-criteria> method: POST
3. Implement the criteria check: In your webhook, implement the logic to check if the user matches your specific criteria. If they do, you can either: a) Return a response that tells Ory to require 2FA for this user, or b) Set a flag in the user's traits indicating they require 2FA 4. Enforce 2FA: After registration, you can enforce 2FA for these users by using step-up authentication. You can trigger this by initiating a new login flow with the aal
parameter set to `aal2`: /self-service/login/browser?aal=aal2
Or for API-based flows: /self-service/login/api?aal=aal2
5. Implement a login hook: To consistently enforce 2FA for these users, you should also implement a login hook that checks the user's criteria or the flag you set during registration, and requires step-up authentication if necessary. Remember that the exact implementation will depend on your specific criteria and how you want to store and check this information. For more detailed information on implementing custom logic with webhooks and configuring step-up authentication, you can refer to the [Hooks documentation](https://www.ory.sh/docs/kratos/hooks/configure-hooks) and the [Step-up authentication documentation](https://www.ory.sh/docs/kratos/mfa/step-up-authentication). It's important to note that while this approach allows you to enforce 2FA for specific new users, you should thoroughly test it in a non-production environment before applying it to your live system. Also, consider how this might affect user experience and have a clear communication plan for users who will be required to set up 2FA.few-oyster-74399
01/15/2025, 4:29 PMbrief-egg-61061
01/15/2025, 4:29 PMbrief-egg-61061
01/15/2025, 4:29 PMaal2
. Here's how you can configure this: 1. In your Ory Identities (Kratos) configuration, you can set the required AAL for user sessions and settings: yaml selfservice: flows: settings: required_aal: highest_available session: whoami: required_aal: highest_available
This configuration enforces the highest available authentication level (which includes 2FA if configured) for accessing user settings and for all user sessions. 2. You also need to ensure that at least one second-factor authentication method is enabled. This could be TOTP, WebAuthn, or SMS-based one-time codes. For example, to enable TOTP: yaml selfservice: methods: totp: config: issuer: YourCompanyName enabled: true
By setting these configurations, you're enforcing 2FA for all users across your application. Users will be required to set up and use a second factor to authenticate and access their accounts. For more detailed information on configuring multi-factor authentication and enforcing AAL levels, you can refer to the [Step-up authentication documentation](https://www.ory.sh/docs/kratos/mfa/step-up-authentication). Remember to thoroughly test these changes in a non-production environment before applying them to your live system, as this will significantly impact your users' authentication process.