Hello Keycloak community,
I have implemented an Email OTP Authenticator and integrated it into the Browser Authentication Flow with a Conditional User Attribute check. This ensures that Email OTP is only prompted if the mfa_enabled
user attribute is set.
For new users, I have a custom Event Listener SPI that automatically sets mfa_enabled=true
during the REGISTER event, requiring all new users to log in with Email OTP. This part works seamlessly.
Issue: Enabling Email OTP MFA for Existing Users
I need to provide a seamless way for existing users to enable Email OTP MFA from my client application. The flow is as follows:
- If
mfa_enabled
is not present in the JWT, the client app prompts the user to enable Email OTP MFA. - Until now, users were not required to provide a real email address. We want to allow users to update their email to one they have access to.
- After updating their email, they receive an OTP to the new email address for verification.
- Only after successful OTP verification should
mfa_enabled
be set totrue
, enforcing Email OTP for subsequent logins.
Initial Approach & Challenge
I initially considered implementing two new Required Actions:
- Email Update (to allow users to update their email).
- Email OTP Verification (to verify the updated email).
I also planned to support Application Initiated Actions for these steps. However, since these are two separate Required Actions, the client app would have to manually orchestrate the flow—first triggering the email update, then triggering OTP verification. This is not ideal.
I would prefer Keycloak to orchestrate this entire process instead of relying on the client app.
Additional Requirement: Enforcing Email OTP for Sensitive Actions
Once Email OTP MFA is enabled, I also want to enforce OTP verification for sensitive account actions, including:
- Username updates
- Password changes
- Account deletion
However, I do not want to force a full re-login before these actions—only an Email OTP prompt for additional security.
Questions:
- What is the best way to structure this Email Update + Email OTP flow within Keycloak without requiring client-side orchestration?
- Is there a way to combine both actions into a single Required Action?
- How can I enforce Email OTP verification for sensitive actions without requiring a full re-login?
I appreciate any suggestions or best practices from the community.
Thanks!