Keycloak MFA

Keycloak multi-factor authentication with OTP, WebAuthn and conditional MFA

Every Keycloak realm can ask for a second factor at sign-in. This page shows where each factor lives in the admin console, the realm settings behind it, and how to ask for it only where it matters.

21-day trial, no card required.  ·  Runs on managed Keycloak.

TOTP and HOTPWebAuthn and passkeys Conditional and step-up MFA

Does Keycloak support multi-factor authentication?

Yes. Keycloak supports MFA out of the box with two kinds of second factor: OTP codes from TOTP and HOTP authenticator apps, and WebAuthn security keys and passkeys. Each factor is a step in the realm's authentication flow, so you decide where it runs. Conditional sub-flows ask for the second factor only from certain users, roles or clients, and step-up authentication asks for it again before a sensitive action.

Up to 99.99% SLASOC 2 Type IIISO 27001GDPR CompliantGlobal residency
Trusted by engineering teams at
DigiCertGoogleRedsenseRovaRhoImpactiSolvedAmazonArcstone

OTP with authenticator apps

Keycloak's OTP factor accepts time-based (TOTP) and counter-based (HOTP) codes from apps such as Google Authenticator, Microsoft Authenticator and FreeOTP. You set the code format for the whole realm under Authentication then Policies then OTP Policy: the type, the hash algorithm, six or eight digits, the period and the look-ahead window. The defaults, TOTP with SHA1, six digits and a 30 second period, work with every common app.

Users register an app through the Configure OTP action under Authentication then Required actions, and turning on its Set as default action switch asks every new user to do so at their next sign-in. In the default browser flow under Authentication then Flows, the OTP Form sits in the Browser - Conditional 2FA sub-flow, which asks for a code from every user who has registered one.

realm.json: OTP policy (the defaults)JSON
{
  "otpPolicyType": "totp",
  "otpPolicyAlgorithm": "HmacSHA1",
  "otpPolicyDigits": 6,
  "otpPolicyPeriod": 30,
  "otpPolicyLookAheadWindow": 1,
  "otpPolicyCodeReusable": false
}

WebAuthn security keys and passkeys

WebAuthn lets a user confirm a sign-in with a security key, or with a passkey kept on their phone, laptop or password manager, and Keycloak uses it in two ways. As a second factor, the user types a password and then confirms with the key: enable Webauthn Register under Authentication then Required actions, and set WebAuthn Authenticator to Alternative in the Browser - Conditional 2FA sub-flow under Authentication then Flows. Its settings are under Authentication then Policies then Webauthn Policy.

For a passkey sign-in with no password, switch on Enable Passkeys under Realm settings then Login, and enable Webauthn Register Passwordless under Required actions. Since Keycloak 26.4 the default login form then offers passkeys through browser autofill and a Sign in with Passkey button, using the settings under Authentication then Policies then Webauthn Passwordless Policy.

realm.json: passkey policyJSON
{
  "webAuthnPolicyPasswordlessRpEntityName": "Example",
  "webAuthnPolicyPasswordlessSignatureAlgorithms": ["ES256", "RS256"],
  "webAuthnPolicyPasswordlessUserVerificationRequirement": "required",
  "webAuthnPolicyPasswordlessPasskeysEnabled": true
}

Conditional and step-up MFA

A conditional sub-flow runs its second factor only when the condition steps at its top are true. Under Authentication then Flows, duplicate the browser flow, add a sub-flow set to Conditional, and start it with a condition: Condition - user role to ask only admins, Condition - client scope to ask only in clients that carry a given client scope, or Condition - user attribute for a group of users. The OTP Form or WebAuthn Authenticator after the condition is then asked only of the users it matches. Bind the copy as the realm's browser flow, or override it for one client in that client's Advanced tab.

Step-up authentication asks for a stronger factor before a sensitive action. Map ACR values to levels of authentication under Realm settings then General, give each level a sub-flow that starts with Condition - Level of Authentication, and have your application request the level it needs with the acr_values parameter. A user who signed in with a password alone is asked for the second factor only when they reach the action that needs it.

realm.json: condition settingsJSON
"authenticatorConfig": [
  {
    "alias": "admins-only",
    "config": { "condUserRole": "admin", "negate": "false" }
  },
  {
    "alias": "step-up-level-2",
    "config": { "loa-condition-level": "2", "loa-max-age": "300" }
  }
]
Capabilities

Enterprise Capabilities

Everything you need for secure, scalable authentication

TOTP and HOTP codes

Codes from Google Authenticator, Microsoft Authenticator, FreeOTP and other standard authenticator apps.

Security keys

WebAuthn hardware keys as a second factor after the password.

Passkeys

Sign-in with a passkey and no password, offered by the default login form since Keycloak 26.4.

Conditional MFA

A second factor only for the roles, clients or users you choose.

Step-up authentication

A stronger factor before a sensitive action, requested with ACR values.

Recovery codes

One-time backup codes for users who lose their authenticator.

Go Live in 3 Steps

From zero to production in minutes, not months

1

Create Your Instance

Sign up and deploy your Keycloak instance. One click, fully managed.

2 minutes
2

Customize Your Branding

Add your logo, colors, and styling to make login pages match your brand.

5 minutes
3

Integrate Your App

Use existing Keycloak SDKs or standard OIDC/SAML libraries for any framework.

15 minutes
Start Free Trial

No credit card required. 21-day free trial with full access.

FAQ

Frequently Asked Questions

Does Keycloak support SMS for MFA?
Keycloak has no native SMS OTP factor. Its built-in second factors are one-time codes from authenticator apps (TOTP and HOTP) and WebAuthn security keys and passkeys, and SMS codes would need a third-party extension and an SMS provider. Because SMS codes can be stolen through SIM swapping and phishing, we recommend authenticator apps and passkeys instead.
Can I require MFA only for admins?
Yes. In the realm's browser flow, add a conditional sub-flow that starts with the "Condition - user role" step set to your admin role, followed by the OTP Form or the WebAuthn Authenticator. Users with that role are asked for a second factor, and everyone else signs in with their password alone.
Should I use passkeys or OTP?
Passkeys resist phishing, because the browser only offers a passkey to the site it was registered for, while a six-digit OTP code can be typed into a fake login page. OTP works with any authenticator app and is a sound second factor where passkeys are not available yet. Keycloak supports both, so many teams offer passkeys first and keep OTP as the fallback.

Ready to Get Started?

Start your free trial today. Full access to all features for 21 days.

No credit card required21-day free trialFull feature accessCancel anytime
© 2026 Skycloak. All Rights Reserved. Design by Yasser SolimanKeycloak™ is a trademark of the Linux Foundation. Skycloak is not affiliated with the Keycloak project.