What Is a Login Flow in Keycloak? — The recipe behind every sign-in

What Is a Login Flow in Keycloak? — The recipe behind every sign-in

A complete, beginner-friendly breakdown of how Keycloak decides, step by step, what a user must do to prove who they are — and how you can reshape that process yourself.

Imagine boarding a flight. You don’t just walk up and get on the plane. You check in, show your passport, walk through security, sometimes get a random extra pat-down, scan your boarding pass at the gate, and only then step onto the plane. Some passengers skip the pat-down because they’re pre-approved. Some airports add an extra fingerprint scan. Every airport follows roughly the same idea — verify who you are before letting you through — but the exact sequence of steps can differ from airport to airport, and even from passenger to passenger. A login flow in Keycloak is exactly this: a configurable sequence of checks a user must pass through before they’re allowed in, and just like an airport, that sequence can be customized, reordered, and made conditional depending on the situation.

1What Is a Login Flow?

Let’s start with the plainest possible definition before adding any complexity.

A login flow in Keycloak is an ordered sequence of individual authentication steps that a user must go through to prove their identity. Instead of authentication being one single, fixed action — “type a password” — Keycloak treats it as a small, configurable pipeline made of separate, swappable pieces, each one checking something specific: a password, a one-time code, a trusted device, or even a decision based on conditions like the user’s role or location.

Simple Analogy

Think of a login flow like a recipe card in a kitchen. The recipe lists steps in order: chop the onions, heat the pan, add the spices, simmer for ten minutes. Each step is a separate, well-defined action, and the order matters. Keycloak’s login flow is the same idea applied to proving identity — “check the username,” then “check the password,” then, if needed, “check a one-time code” — and just like a recipe, you can swap ingredients, add an optional garnish, or make an entire step conditional on what’s in the pantry.

Term

Flow

The overall named sequence of steps — for example, “browser login flow.”

Term

Execution

A single step inside a flow — one specific check or action to perform.

Term

Authenticator

The actual piece of logic behind an execution — the code that performs the password check, the OTP check, etc.

Term

Requirement

A setting on each execution stating whether it’s Required, Alternative, Conditional, or Disabled.

Login flows are one of Keycloak’s most powerful and most distinctive features. Where many simpler systems hard-code “username and password, that’s it,” Keycloak lets administrators visually design exactly what a user must do to sign in — and different flows can be applied to different situations, like a stricter flow for administrators than for regular customers.

2Why Login Flows Exist — The Problem They Solve

Before flows existed as a concept, authentication logic was usually rigid and hard to change.

In many older or simpler systems, “how login works” is baked directly into the application’s code. If a company later decides it wants to add multi-factor authentication, or skip the password step for trusted devices, or require an extra check only for admin accounts, a developer has to go dig into the code and rewrite the login logic by hand — risky, slow, and error-prone for something as sensitive as authentication.

!
The Old Way’s Problem

Hard-coded login logic means every new requirement — a new MFA method, a new condition, a new fallback — requires a code change, a full test cycle, and a redeploy, even though the underlying goal (verify the user) hasn’t changed at all.

Keycloak’s login flow system solves this by turning authentication into configuration instead of code. Administrators can rearrange, add, remove, or make steps conditional entirely through the admin console, without touching a single line of application code. This is what makes login flows so valuable in real-world identity management — they let security requirements evolve quickly as an organization’s needs change.

No Code
Changes Needed to Adjust Login
Reusable
Steps Across Many Flows
Per-Client
Flows Can Differ by Application

3The Core Building Blocks: Flows, Executions, and Authenticators

Just like the recipe-card analogy, let’s meet the actual pieces that make up a flow.

Flow

A flow is the top-level container — a named sequence like “Browser,” “Direct Grant,” or a custom flow an administrator built, such as “High-Security Admin Login.”

Sub-Flow

A flow can contain a nested mini-flow inside it, grouping a few related executions together — for example, a “Multi-Factor” sub-flow containing both “OTP Form” and “WebAuthn” as alternative options within it.

Execution

Each individual line inside a flow is an execution — a single, specific checkpoint, like “Username Password Form” or “OTP Form.”

Authenticator

Behind every execution sits an authenticator — the actual logic that performs the check. Keycloak ships with many built-in authenticators, and custom ones can be added by developers.

Simple Analogy

If the flow is the recipe, the executions are the individual steps written on the card (“preheat oven,” “whisk eggs”), and the authenticator is the actual kitchen tool or technique used to carry out that step. Two different recipes might both have a “whisk eggs” step, reusing the same technique — just like two different login flows can both reuse the same “OTP Form” authenticator.

Built-in

Username Password Form

Collects and checks a username and password together.

Built-in

OTP Form

Asks for a time-based one-time code, usually from an authenticator app.

Built-in

WebAuthn Authenticator

Verifies a security key or biometric like a fingerprint, using the WebAuthn standard.

Built-in

Identity Provider Redirector

Sends the user to log in through an external provider, like a social login or a partner company’s identity system.

4Architecture — Where Login Flows Fit Inside Keycloak

Zooming out to see how login flows connect to the rest of a realm’s configuration.

Component

Realm

Every realm has its own independent set of flows — the “Browser” flow in one realm doesn’t affect another realm.

Component

Authentication Engine

The internal component that reads a flow definition and actually walks through it, execution by execution, during a real login attempt.

Component

Client Binding

A client application can be assigned a specific flow, allowing one app to require stricter authentication than another within the same realm.

Component

Authenticator Registry

The catalog of all available authenticator types — built-in and custom — that can be added as an execution inside any flow.

Simple Analogy

A realm is like a whole country with its own passport rules. Within that country, different airports (client applications) might apply different levels of screening — a small regional airport might just check your ticket, while an international hub applies a stricter, multi-step process. Both airports still belong to the same country’s overall system, and both draw from the same catalog of available screening techniques.

5How a Login Flow Executes, Step by Step

Now let’s trace exactly what happens internally when a real user tries to log in.

When someone attempts to log in, Keycloak’s authentication engine loads the relevant flow and walks through its executions from top to bottom, evaluating each one’s requirement level as it goes.

1

User Reaches the Login Endpoint

The application redirects the user’s browser to Keycloak to begin authentication.

2

Engine Loads the Assigned Flow

Keycloak determines which flow applies — based on the client, or the realm’s default “Browser” flow.

3

First Execution Runs

Typically the username/password form is displayed and submitted for checking.

4

Requirement Level Is Checked

If the step is Required and it fails, the whole flow stops and login is denied. If it’s Alternative, a different step in that group may be tried instead.

5

Conditional Logic Is Evaluated

If a step is Conditional (e.g., “only require OTP for admin role”), the engine checks the condition before deciding whether to run it.

6

Next Execution Runs

The engine moves to the next step in order, repeating the same evaluation process.

7

All Required Steps Pass

Once every Required (and applicable Conditional) execution succeeds, the flow completes.

8

Tokens Are Issued

Keycloak generates the signed tokens and redirects the user back to the application, now authenticated.

sequenceDiagram
    participant U as User
    participant App as Application
    participant KC as Keycloak Engine
    U->>App: Attempt to access app
    App->>KC: Redirect to login
    KC->>U: Show Step 1 (Username/Password)
    U->>KC: Submit credentials
    KC->>KC: Evaluate requirement + condition
    KC->>U: Show Step 2 (OTP, if required)
    U->>KC: Submit OTP code
    KC->>KC: All required steps passed
    KC-->>App: Issue tokens, redirect back
    App-->>U: Access granted
        
FIG 1 — A login flow executing two sequential steps before granting access

6Data Flow and Lifecycle — From Browser to Token

A broader view of how a login flow fits inside the entire authentication lifecycle.

flowchart TD
    A[Login Flow Defined in Admin Console] --> B[Flow Assigned to Realm or Client]
    B --> C[User Initiates Login]
    C --> D[Engine Executes Flow Step by Step]
    D --> E{All Required Steps Passed?}
    E -->|Yes| F[Session Created and Tokens Issued]
    E -->|No| G[Login Denied, Attempt Logged]
        
FIG 2 — The full lifecycle from designing a flow to a completed login attempt

Notice that the flow itself is designed once, ahead of time, by an administrator — but it’s executed fresh, from the beginning, for every single login attempt. This separation between “designing the process” and “running the process” is exactly what makes login flows reusable and easy to reason about.

7The Built-in Flows Keycloak Ships With

Keycloak comes with several ready-made flows out of the box, each serving a different purpose.

Flow NamePurpose
BrowserStandard login flow used when a user interacts through a web browser
Direct GrantUsed when an application exchanges a username and password directly for tokens, without a browser redirect
RegistrationGoverns the steps a new user goes through when creating an account
Reset CredentialsControls the “forgot password” recovery process
First Broker LoginRuns the first time a user logs in through an external identity provider, to link or create an account
ClientsHandles authentication for applications themselves (client credentials), not human users
i
Good to Know

None of these built-in flows are locked in place — every one of them can be copied and customized. Best practice is to duplicate a built-in flow before editing it, so the original stays available as a safe fallback.

8Requirement Levels — Required, Alternative, Conditional, Disabled

This single setting is what gives login flows their real power and flexibility.

Every execution inside a flow has a requirement level, and understanding these four options is the key to designing a flow correctly.

Level

Required

The user must pass this step. If it fails, the entire login attempt fails.

Level

Alternative

Grouped with other Alternative steps — the user only needs to pass one of them, useful for “log in with password OR with a security key.”

Level

Conditional

A sub-flow that only runs if a specified condition is true, such as the user’s role or whether OTP is already configured.

Level

Disabled

The step is skipped entirely — kept in the flow definition but effectively turned off.

Simple Analogy

Think of airport security lanes. “Required” is like the mandatory metal detector everyone must pass through. “Alternative” is like choosing between the regular security line or the pre-approved fast-track line — you only need to succeed at one of them. “Conditional” is like the random additional pat-down applied only to some passengers based on a rule. “Disabled” is a lane that exists on the airport map but is currently closed and unused.

9Advantages, Disadvantages, and Trade-offs of Customizing Flows

Flexibility is powerful, but it comes with real design responsibility.

Advantages

  • Change authentication requirements without writing or redeploying code
  • Apply different strictness levels to different applications or user groups
  • Add new authentication methods (biometrics, hardware keys) as plug-in steps
  • Reuse the same authenticator across many different flows
  • Test new flows safely by duplicating and editing a copy first

Disadvantages / Trade-offs

  • Overly complex flows become hard to understand and maintain
  • Misconfigured requirement levels can accidentally weaken security
  • Conditional logic that’s poorly tested can lock out legitimate users
  • Custom authenticators require careful development and security review
!
Trade-off to Remember

Every extra Alternative step you add is, by definition, another way in — if any one of several alternatives is weak, an attacker will simply use the weakest one. Flexibility must be balanced against not accidentally creating an easy bypass.

10Security Considerations in Login Flow Design

Since a login flow is literally the front door, small design mistakes here have outsized consequences.

Avoid Weak Alternative Paths

If “password” and “email magic link” are both Alternative options, and the email account is compromised, the attacker can simply bypass the password entirely. Every Alternative branch should be roughly as strong as the others.

Use Conditional Steps for Risk-Based Authentication

A well-designed flow can require extra verification only in higher-risk situations — an unfamiliar device, an admin role, or a login from an unusual location — rather than annoying every single user with the strictest possible checks all the time.

Simple Analogy

A bank doesn’t ask every customer walking in to make a small deposit to show three forms of ID — but it absolutely does for someone trying to withdraw their entire life savings in cash. Conditional steps let a login flow apply exactly that kind of proportional scrutiny.

Protect the Recovery Flow as Strongly as the Login Flow

The “Reset Credentials” flow is often overlooked, yet it’s frequently the easiest path for an attacker — if resetting a password is weaker than logging in directly, attackers will target the reset flow instead.

ANTI-PATTERN-01 Avoid
Problem

Making multi-factor authentication an Alternative step instead of Required, so a user can simply choose password-only login.

Why It’s Harmful

This defeats the entire purpose of adding MFA — a determined attacker with a stolen password will just pick the weaker alternative and skip the second factor completely.

Correct Approach

Place MFA as a Required step (or a Conditional step that becomes Required under risk conditions) after the password step, not as an alternative to it.

11Monitoring, Logging, and Metrics for Login Flows

A flow’s design only matters if you can also see how it behaves in the real world.

Signal

Step Failure Rate

Tracking which execution inside a flow fails most often can reveal a confusing UI or a genuinely broken step.

Signal

Conditional Branch Frequency

How often a conditional step actually triggers helps verify the underlying condition is working as intended.

Signal

Time to Complete Login

A flow with too many required steps may frustrate users — measuring total login time helps balance security against convenience.

Signal

Repeated Failed Attempts

Spikes at a specific step, especially the password check, can indicate a brute-force attempt worth investigating.

i
Why This Matters

Every step evaluated in a login flow can be logged, giving administrators visibility not just into whether someone logged in, but exactly which path they took to get there — invaluable when investigating a suspicious login later.

12Design Patterns and Anti-Patterns

Some flow designs age gracefully. Others quietly become maintenance nightmares.

Pattern: Duplicate Before You Customize

Copy a built-in flow before editing it, so the original, known-good version remains available as a fallback if something goes wrong.

Pattern: Use Conditional Sub-Flows for Risk-Based Rules

Group risk-based logic into a clearly named sub-flow (e.g., “Admin Extra Verification”) rather than scattering conditions across the top-level flow.

Pattern: Assign Different Flows to Different Clients

A public customer-facing app and an internal admin dashboard can safely use different flows with different strictness levels, even within the same realm.

ANTI-PATTERN-02 Avoid
Problem

Building one giant, deeply nested flow meant to handle every possible scenario for every application in a single realm.

Why It’s Harmful

A single, overloaded flow becomes extremely difficult to reason about, test, and safely modify — a change meant for one application can accidentally break login for a completely different one.

Correct Approach

Create separate, purpose-specific flows for distinct applications or user populations, even if that means some duplication between them.

13Best Practices and Common Mistakes

A practical checklist for anyone designing or reviewing a login flow.

Best Practice

Test Every Branch

Manually walk through each Alternative and Conditional path before relying on it in production, including failure cases.

Best Practice

Document Custom Flows

Keep a clear written record of why a flow was customized and what each unusual step is meant to do.

Best Practice

Keep the Recovery Flow Reviewed

Audit the “Reset Credentials” flow with the same rigor as the main login flow, since it’s a common attack target.

Best Practice

Review Flows After Any New Feature

When adding a new authentication method, revisit existing flows to confirm the new option doesn’t accidentally weaken overall security.

!
Common Mistakes

Frequent mistakes include leaving MFA as Alternative instead of Required, forgetting to test a Conditional branch’s “false” path, editing a built-in flow directly instead of a copy, and never revisiting old flows after new authenticators are introduced.

14Real-World Examples

Seeing login flows applied to concrete situations makes the concept click.

Conditional MFA for Admins Only

A flow where regular users only need a password, but a conditional sub-flow forces an additional OTP step whenever the authenticated user holds an “admin” role.

Passwordless Login with WebAuthn

A flow where the Username Password Form is replaced entirely with a WebAuthn step, letting users sign in with a fingerprint or hardware security key instead of typing anything.

Social Login Alongside Traditional Login

A flow offering “log in with company credentials” and “log in with Google” as Alternative steps, so users can pick whichever they prefer.

Stricter Flow for a Banking Application

The customer-facing website uses the standard browser flow, while the internal transaction-approval dashboard is bound to a separate, stricter flow requiring both a password and a hardware key, every time.

Across all of these, the underlying mechanism never changes — only the executions chosen, their order, and their requirement levels. This is precisely why login flows are considered one of the most reusable and powerful design tools inside Keycloak.

15Frequently Asked Questions

Q1Can different applications in the same realm use different login flows?

Yes. A specific flow can be bound to an individual client application, so one app can require stricter authentication than another, even though both belong to the same realm.

Q2What happens if a Required step fails?

The entire login attempt fails immediately. Required steps must all succeed — there’s no way to proceed past a failed Required execution.

Q3Is it safe to edit the built-in “Browser” flow directly?

It’s generally safer to duplicate it first and edit the copy. This keeps a known-working fallback available in case the customization introduces an unexpected issue.

Q4How is a Conditional step different from an Alternative step?

An Alternative step is one of several options a user can freely choose among to satisfy that part of the flow. A Conditional step isn’t a user choice at all — it’s automatically included or skipped based on a rule, such as the user’s role.

Q5Can I add my own custom authentication step that isn’t built in?

Yes. Keycloak supports custom authenticators, which developers can build and register, allowing entirely new verification methods to be plugged into any flow alongside the built-in ones.

Q6Does the order of steps in a flow matter?

Yes, the engine evaluates executions strictly in the order they’re arranged. This is why, for example, a password check is typically placed before an OTP check — the user’s basic identity should be confirmed before asking for a second factor.

16Summary and Key Takeaways

A login flow in Keycloak turns authentication from a single, rigid step into a configurable, ordered sequence of individual checks — each one an execution backed by an authenticator, each one marked as Required, Alternative, Conditional, or Disabled. This design lets administrators reshape how users prove their identity entirely through configuration, applying different strictness levels to different applications, adding new authentication methods without writing code, and building proportional, risk-based rules that only demand extra verification when it’s actually warranted. Like any powerful tool, flows require careful design — a poorly placed Alternative branch or an untested Conditional path can quietly weaken security instead of strengthening it. Understood well, though, login flows are one of the clearest examples of how Keycloak turns something as sensitive as authentication into something transparent, flexible, and genuinely manageable.

Key Takeaways

  • A login flow is a configurable sequence of authentication steps. — It replaces hard-coded login logic with flexible, admin-configurable pieces.
  • Flows are built from executions, each backed by an authenticator. — These are the reusable Lego bricks that make up any flow.
  • Requirement levels — Required, Alternative, Conditional, Disabled — define behavior. — This single setting controls whether a step is mandatory, optional, rule-based, or skipped.
  • Keycloak ships with several purpose-built flows. — Browser, Direct Grant, Registration, Reset Credentials, First Broker Login, and Clients each serve a distinct scenario.
  • Different applications can use different flows. — Strictness can be tailored per client, not forced uniformly across an entire realm.
  • Security depends on correct requirement-level choices. — Placing MFA as Alternative instead of Required, for example, quietly defeats its purpose.
  • Always duplicate before customizing a built-in flow. — This keeps a safe, known-working fallback available if a change goes wrong.