Multi-Factor Authentication (MFA) β
Overview β
Multi-factor authentication (MFA) serves as a fundamental security measure designed to fortify account protection. By integrating an additional layer of authentication, MFA requires verification of both primary and secondary factors to grant access to an account. Typically, the primary factor revolves around an email address, while the secondary factor involves a phone number or a mobile device authenticator. The premise behind MFA is that compromising both factors is necessary to breach an account, thus significantly bolstering security.
In practice, primary factors can encompass various forms such as email, SMS, or social login credentials, while secondary factors often involve mobile authenticator apps like Google Authenticator, Microsoft Authenticator, 2FAS (open-source) or physical security key like YubiKey. These secondary factors provide an added level of security by generating unique codes or prompts that must be validated alongside primary credentials.

Use Case β
IAM β
MFA is commonly used in customer-facing applications to ensure a high level of security for online services such as e-commerce platforms, mobile applications, and online banking. It significantly reduces the risk of unauthorized access, enhancing both security and user trust.
CIAM β
In business-to-business (B2B) scenarios, MFA serves the needs of companies looking to streamline access for their partners or vendors. By integrating MFA with existing external systems such as Active Directory (AD) or LDAP, organizations can centralize account management and enforce stringent security measures. This facilitates secure collaboration while maintaining robust security protocols.
IdP Broker β
MFA is also beneficial for Identity Provider (IdP) brokers, where it can be used to enhance the security of federated identities. By adding an extra layer of security, it ensures that users accessing services through federated login are thoroughly verified.
Pros & Cons β
Pros β
Enhanced Security: MFA significantly reduces the risk of unauthorized access by requiring multiple forms of verification.
Increased User Trust: By providing a higher level of security, MFA enhances user trust and confidence in the application.
Compliance: Helps meet regulatory requirements and industry standards for data protection and security.
Cons β
Deteriorated User Experience: MFA introduce additional steps in the login process, which may affect user convenience.
Device or App availabilities: Users need devices with the App or a physical key to support the mfa, which may limit accessibility for some users.
Supported by Keycloak β
Yes, natively supported and configurable on Managed Keycloak by Cloud-IAM.
Configuration β
How to configure OTP-Based MFA in Keycloak for new users using Google Authenticator β
This step-by-step tutorial guides how to configure Multi-Factor Authentication (MFA) using Google Authenticator in Keycloak. Itβs designed to help you quickly set up and test OTP-based authentication for new users in one of the realms of your Keycloak deployment.
In this guide, we assume that your Keycloak environment either has no users yet or that MFA is not required for existing users. Only newly registered users will be prompted to configure OTP via an authenticator app like Google Authenticator during their first login.
This tutorial does not cover all the necessary security best practices for a complete configuration.
Keycloak console - Realm setting β
- Login to your Keycloak as an admin
- From your keycloak console, select your realm from the dropdown list (here : tutorial-demo)
- Click on
Authentication
- Then click on
Required actions
- Enable
Configure OTP
on Set as default action section.

Conclusion - Enforcing MFA for new users β
The all new users will now be forced to configure Multi-Factor Authentication (MFA). They will be prompted to register an OTP device, such as Google Authenticator.
Once MFA is configured, users must enter a 6-digit OTP code during each login.
How to configure OTP-Based MFA in Keycloak user per users using Google Authenticator β
This step-by-step guide explains how to set up OTP-based Multi-Factor Authentication (MFA) in Keycloak for individual users using Google Authenticator. It is designed to help you enable and test MFA for a specific user in one of your Keycloak realms.
This tutorial assumes that your Keycloak instance already has at least one user. Only the configured user will be prompted to set up OTP and during their next login using an authenticator app. To enable OTP for other users with this method repeat this process or apply it during future enrollments byfollowing this tutorial.
This tutorial does not cover all the necessary security best practices for a complete configuration.
Keycloak console - Require OTP for existing user β
- Login to your Keycloak as an admin
- Select the realm where the user is located
- Navigate to
Users
section (1.) - Find and select the user you want to enable MFA for (here : user-demo)
- In the
Required user actions
dropdown list, chooseConfigure OTP
(2. & 3.) - Click
Save
to confirm and apply changes

Conclusion - Enforcing MFA for user per user β
The selected user (e.g., user-demo
) will now be forced to configure Multi-Factor Authentication (MFA) at their next login. They will be prompted to register an OTP device, such as Google Authenticator.
Once MFA is configured, the user must enter a 6-digit OTP code during each login.
How to configure OTP-Based MFA in Keycloak for users by role using Google Authenticator β
This step-by-step guide shows how to enable OTP-based Multi-Factor Authentication (MFA) in Keycloak for users with a specific role using Google Authenticator. It helps you activate MFA for all users assigned to a particular role in your Keycloak realm, using new authentication browser flow.
This tutorial assumes your Keycloak instance has users assigned to the target role, for the example the admin role from the master realm will be used. Only users with the configured role will be prompted to set up OTP during their next login using an authenticator app. This method can be apply with a manually assigned role or as part of a user group inheriting a role.
This tutorial does not cover all the necessary security best practices for a complete configuration.
Keycloak console - Duplicate browser flow β
- Login to your Keycloak as an admin
- Select the realm that contains the target role
- Navigate to
Authentication
(1.) - Select
Browser
from the list (2.) - Click on
Action
and chooseDuplicate
(3.) - Name the new browser flow like browser - admin OTP flow

Keycloak console - Configure browser flow β
- Delete the line browser - admin OTP flow Browser - Conditional OTP by clicking on ποΈ
- Add a new execution step :
- Click
οΌ
from the line browser - admin OTP flow form - Select
Add Execution
- From the list select
Conditional OTP form
, then clickAdd
- Directly change its status from
Disable
toRequired

Keycloak console - Configure conditional OTP form based on Role β
- Select the βοΈ next to Conditional OTP form
- Assign an Alias like mandatory OTP for admin (1.)
- On Force OTP for Role click on
Select Role
- Select the filter
Filter by realm role
- Click on the role here
admin
(description : 'role_admin') then clickAssign
(2.) - Then Click
Save

Keycloak console - Bind the new created browser flow β
- Click on
Action
and selectBind the flow
- From the list choose
Browser flow
and click onSave
- Navigate to
Authentication
- Verify that the flow is bind by browser - admin OTP flow should appear on top of the list with a β on *Used by section.

Conclusion - Enforcing MFA for Users by Role β
The selected role (e.g., admin) will now be forced to configure Multi-Factor Authentication (MFA) at their next login. They will be prompted to register an OTP device, such as Google Authenticator.
Once MFA is configured, all users with this role must enter a 6-digit OTP code during each login.
MFA Initialization and Usage for the user β
Keycloak user login screen - MFA first authentication or registration β
During the initial MFA authentication, the new user enters their username and password, followed by a prompt to register for MFA.
- Download and Open your Google Authenticator App on your mobile
- Click on
+
- Select
Scan a QR Code
- On your Keycloak Login Screen fill in the password (6 character)
- Enter the name of your device
- Then click on
Submit

Keycloak login screen - MFA usual authentication β
During a typical MFA-authenticated login, the user enters their username and password, then inputs the 6-digit code generated by Google Authenticator.
