Tuning Keycloak after installation: realm settings, client settings, authentication flows, password policies, plus SMTP and reverse proxy configuration for production use.

In episode 19 you successfully installed Keycloak and made sure the database is connected. Episode 20 is about tuning that instance so it's ready to use: per-realm settings, client settings, authentication flows, password policies, SMTP for transactional email, and configuration behind a reverse proxy. This is the episode that touches the admin console the most.
Almost all settings live in the Realm Settings menu and apply per realm. Here are its main categories.
Contains the realm name, alias, and display mode. The realm name determines part of the URL — id.example.com/realms/myrealm — so choose a name that stays stable and consistent from the start.
This section controls login behavior: whether users can self-register (registration), the forgot password button, email verification, and remember me. The Default groups setting from episode 18 is also here.
Keycloak signs tokens with a key pair managed per realm. Three key types are common:
| Key Type | Function |
|---|---|
| RSA | Signs JWTs, e.g. RS256 |
| HMAC | Symmetric signing, e.g. HS256 |
| AES | Token encryption |
The RSA key pair is generated automatically when the realm is created. Rotation and new key generation are done from the Keys tab.
SMTP is needed for password reset emails, account verification, and notifications. It can be configured via the Email tab in the admin console or via environment variables:
KC_SMTP_HOST=smtp.example.com
KC_SMTP_PORT=587
KC_SMTP_FROM=no-reply@example.com
KC_SMTP_AUTH=true
KC_SMTP_USERNAME=noreply
KC_SMTP_PASSWORD=rahasia
KC_SMTP_STARTTLS=trueAlways test with the "test connection" feature and send a real password reset email after configuring SMTP — this is the path that most often fails in production.
Determines the login, account, admin, and email themes per realm. Full details are in episode 21.
Sets the default language and available languages for login pages and emails. Combine with a custom message bundle so your preferred language is truly used.
Configures security headers (Content-Security-Policy, X-Frame-Options, and others) as well as brute force detection. This will be covered in depth in episode 24.
When Keycloak is installed behind a reverse proxy terminating TLS, tell it via KC_PROXY. The edge mode means TLS is terminated at the proxy, and Keycloak reads the forwarded headers:
KC_PROXY=edge
KC_HOSTNAME=id.example.com
KC_HOSTNAME_STRICT=trueWithout this setting, Keycloak can infer the protocol incorrectly and produce redirects with an HTTP scheme.
Clients represent the applications that use Keycloak. Their important settings:
The unique identifier of the application, e.g. webapp or mobile-api. The client ID appears in the authorization URL and in tokens.
Historically Keycloak recognized three access types; recent versions simplify them into the Client authentication toggle:
| Type | Secret | Example usage |
|---|---|---|
| Confidential | Yes | Backend applications that can store a secret |
| Public | No | SPAs and mobile applications |
| Bearer-only | Yes | Gateway that only validates tokens (legacy) |
Server-side applications use confidential; SPAs and mobile apps use public so the secret doesn't leak into the browser.
The list of URIs allowed as redirect destinations after login, e.g. https://app.example.com/callback. Wildcards are available, but being too loose risks open redirect — register URIs explicitly whenever possible.
Origins allowed for cross-origin requests, e.g. https://app.example.com. This is important for public clients so the browser doesn't block calls to Keycloak endpoints.
OIDC or SAML. Most modern applications use OIDC (based on OAuth2 and JWT); SAML is retained for legacy integrations.
Advanced settings for OIDC: token signature algorithm, response mode, and claim shape in userinfo. Adjust to the application's needs, not just defaults.
An authentication flow is the sequence of steps a user goes through. Several built-in flows:
| Flow | Function |
|---|---|
| Browser flow | Main browser login flow, including OTP if enabled |
| Direct grant flow | Direct username/password login via the API |
| Registration flow | New account creation flow |
| Reset credentials flow | Password reset flow via email |
| Custom flows | Custom flows for OTP, WebAuthn, and other steps |
To see the flow list from the terminal: kcadm.sh get authentication/flows -r myrealm. Custom flows for OTP and WebAuthn will be used in episode 23.
Password policies are set in Realm Settings → Authentication → the Policies tab and apply to the entire realm:
| Policy | Meaning |
|---|---|
| Length | Minimum length, e.g. 12 characters |
| Uppercase/Lowercase/Digits/Special chars | Character classes that must be present |
| Expire Password | Password validity period |
| Not Recently Used (History) | Prevents old passwords from being reused |
| Blacklist | Forbids common or weak passwords |
| Hash algorithm | Hashing algorithm; PBKDF2 is the default, can be switched to BCrypt or argon2 |
A common production combination: length 12, all character classes, history 5, and blacklist active. Don't forget these policies only apply to passwords, not to other authentication factors.
In episode 20, you tuned Keycloak: realm settings (general, login, keys, email, themes, localization, security defenses), client settings (ID, access type, redirect URIs, CORS, protocol, fine grain OIDC), authentication flows, password policies, plus SMTP and reverse proxy for production.
Key takeaways:
KC_PROXY=edge for deployments behind a reverse proxy — without it the protocol can be detected incorrectly.In the next episode (episode 21), you'll change Keycloak's look so it doesn't feel generic: Themes & Customization — login, account, admin, email, and welcome themes.