How OAuth2 Proxy adds Keycloak sign-in to apps that have no login
If your internal dashboard or tool has no OIDC support and must sit behind Keycloak, OAuth2 Proxy can handle the sign-in for you by running as a reverse proxy in front of the app and using its keycloak-oidc provider as a confidential client. The application itself is not modified. A user who requests the tool reaches OAuth2 Proxy first, which redirects them to the Keycloak realm to log in. After Keycloak returns an authorization code, OAuth2 Proxy exchanges it on the back channel using the client secret, validates the tokens, sets its own encrypted session cookie, and forwards the request to the upstream app. Requests without a valid session are sent back to the login flow before they reach the app.
The upstream app receives identity as request headers rather than as tokens. Depending on how you configure OAuth2 Proxy, these headers can carry the user name, email address, and group or role claims that the Keycloak client mappers place into the tokens. The app is not built to verify anything, so it has to trust that only OAuth2 Proxy can reach it. That trust depends on network design: the app should listen only on an internal address that the proxy can reach, and any client header with the same names must be stripped or overwritten at the edge. Confirm the exact header names and claim settings against the OAuth2 Proxy documentation for your version before you write any access rules that depend on them.
Plan the Keycloak side before the proxy side. You will need a confidential client with a redirect URI that points to the proxy's callback path, an audience mapper if the token must name the proxy as its audience, and a groups mapper so that group membership reaches the proxy for authorization decisions. Keep the client secret in a secrets store rather than in a flat configuration file, and decide who can rotate it. The Keycloak server administration guide describes client and mapper configuration, and that is where your administrators should confirm the settings for your Keycloak release.
What you need in place before configuring OAuth2 Proxy with Keycloak
OAuth2 Proxy sits between users and an app that has no login of its own, so the proxy, Keycloak and the upstream app all have to be ready before any client is created. The cards below cover the Keycloak deployment, transport security, the callback hostname, network paths and the admin access needed to change the realm.
A Keycloak deployment on a current release
Plan the proxy against a Keycloak deployment you can upgrade on your own schedule. The current release supplied for this work is Keycloak 26.8.1, published October 13, 2026. Confirm which version your environment runs, whether it is a self-managed build or the Red Hat build of Keycloak, and that its database is one of the supported production databases. Client settings described later depend on the admin console layout of the version you run, so record the exact version before you start.
Keycloak docsTLS on every connection
The OAuth2 Proxy redirect flow sends tokens and session cookies between the browser, the proxy and Keycloak, so every hop needs TLS. Keycloak's production guidance calls for TLS on all communication, including the path from the reverse proxy to Keycloak. Confirm which certificate authority issues the certificates, that the proxy trusts the Keycloak issuer certificate chain, and that clients will not fall back to plain HTTP for the callback.
Production guideA reachable public hostname for the callback
OAuth2 Proxy receives the authorization code at a fixed callback path on its own hostname, and Keycloak only redirects to URIs it has registered for the client. Decide the public hostname for the proxy now, such as an illustrative tools.example.internal, and confirm that users' browsers can resolve and reach it. Internal DNS, split-horizon records and load balancer health checks often cause the first failed login, so test the name from the same network segment your users use.
The upstream app's network path
OAuth2 Proxy forwards authenticated requests to the upstream app over a network path you control, so the app must accept connections only from the proxy. Map which address or service name the proxy uses to reach the app, whether the app runs on the same host, in a container network or in another zone, and which firewall rules or service policies allow that flow. Also decide whether the app should be reachable directly by anyone who bypasses the proxy, and block that route.
Admin access to the realm
Creating the confidential client, adding audience and groups mappers, and setting group or role restrictions all require a realm administrator account. Confirm who holds that access, whether changes go through a named change process, and that the admin console is reached on a hostname or path separate from public frontend URLs. Agree in advance who approves the group names the proxy will check, because those names become the access rules for the app.
Server admin guideThe OAuth2 Proxy version and its options
The keycloak-oidc provider settings, flag names and cookie options change between OAuth2 Proxy releases, so the configuration in this guide should not be copied without checking it. Record the release you intend to deploy, read the project's own documentation for that release, and confirm the provider name, the client secret handling, the cookie settings and the group and header options it lists. Treat any example value in this guide as illustrative until you have verified it against that documentation.
Configuring the Keycloak client, mappers and OAuth2 Proxy in sequence
This sequence takes an internal tool with no login of its own from an empty Keycloak realm to a working sign-in gate. Each step leaves a check you can run before moving on, so a failure is traced to one component at a time.
Create a dedicated realm and users for the tool
The Keycloak administrator creates a realm for the internal tools, separate from any realm that holds other applications, so client settings, users and groups can be reviewed in isolation. Create a test group, a test user who belongs to it, and a second user who belongs to no group. Keep both users in the same realm so the group restriction can be tested later. The step is done when both users exist, the first user has a password set, and the administrator can see the group membership on each user's details page.
Register a confidential client with the proxy callback
In the realm, create an OpenID Connect client with client authentication turned on, so Keycloak issues a client secret that only the OAuth2 Proxy server holds. Set the valid redirect URI to the proxy's callback path on the proxy hostname, using the path your OAuth2 Proxy version documents, and avoid wildcard redirect URIs. Store the generated secret in your secrets manager rather than in a shared file. The step is done when the client shows client authentication enabled and the redirect URI matches the exact URL the proxy will serve.
Add audience and groups mappers to the client
Add a mapper that writes the client's own identifier into the access token's audience claim, since OAuth2 Proxy checks that the token was issued for it. Add a second mapper that places the user's group names into a claim, such as a groups claim, in the access or ID token. Confirm the claim name each mapper writes, because the proxy's group restriction setting must match it. The step is done when a token issued for the test user shows the expected audience value and lists the test group.
Decode test tokens to confirm claims
Sign in as the test user through the browser or a token request, then decode the access token and the ID token with a JWT inspection tool in a non-production environment. Check the issuer, the audience, the expiry, and the groups claim. Repeat with the user who has no group. The step is done when the first token carries the group and the audience, and the second token carries no group value that would satisfy the proxy's restriction. Do not paste production tokens into public decoding sites.
Configure OAuth2 Proxy with the keycloak-oidc provider
On the proxy host, set the provider to keycloak-oidc, then supply the issuer URL for the realm, the client ID, the client secret, the cookie secret and the proxy's external URL. Add the group restriction and the allowed-group setting that point at the groups claim you verified in the previous step. Choose whether the proxy should pass identity headers to the upstream and which claim feeds each header. Confirm the exact configuration keys against the OAuth2 Proxy documentation for your installed version. The step is done when the proxy starts without configuration errors and its health endpoint responds.
Route the upstream application behind the proxy
Point the reverse proxy or ingress for the tool's public hostname at OAuth2 Proxy, and set the proxy's upstream to the internal address of the dashboard. Block direct access to the upstream from outside the proxy, so the identity headers cannot be forged by a client that bypasses it. Keep the admin console of the tool on the same gate or restrict it separately. The step is done when an unauthenticated request to the hostname redirects to Keycloak, and the upstream address refuses connections from outside the proxy network.
Verify allowed and denied sign-in paths
Sign in as the test user who is in the group and confirm the dashboard loads and the expected identity headers reach the upstream. Then sign in as the user with no group and confirm the proxy returns a denial rather than the dashboard. Finally, remove the test user from the group in Keycloak, start a new browser session, and confirm access ends. The step is done when all three results match, and the outcome is recorded with the proxy and Keycloak versions you tested.
How audience and groups claims reach the proxy
OAuth2 Proxy does not look up users or groups in Keycloak on each request. It validates the token it receives from the Keycloak sign-in and reads whatever claims that token carries. If the audience mapper and the groups mapper do not add their values to the access token or ID token the proxy validates, the proxy has nothing to check, and group or role restrictions fail closed or silently allow the wrong users. Decide first which token the proxy will validate, then configure the mappers on the client's scope so the claim lands in that token, not only in the userinfo response.
The audience mapper puts the client's own identifier, or the identifier of the API the proxy protects, into the aud claim. Without it, the token may be issued for the account console or another client and fail the proxy's audience check. The groups mapper writes group membership into a claim, usually named groups, which the proxy can match against allowed values. Confirm the exact claim names, whether the groups claim is emitted as full paths or short names, and which proxy options consume them in the OAuth2 Proxy and Keycloak documentation for the versions you run. Test with a real user from each group you intend to allow and with a user outside all of them.
Role-based restrictions depend on what the client's token contains. Realm roles and client roles appear in different claims, and a client role is only present when the client's scope mappings include it for that user. Keycloak's default scopes and the client's scope settings decide what is emitted, so a restriction that works for an administrator may fail for a standard user with a narrower role set. Record the claim each restriction reads, test every role you plan to rely on, and re-test after any change to client scopes, since a missing mapper can look like a policy failure in the proxy logs.
Mapping Keycloak claims to proxy restrictions and upstream headers
This table pairs each Keycloak token claim the integration relies on with the OAuth2 Proxy setting that reads it and the header or access decision it produces for the upstream app. Read each row as a chain: the mapper puts the claim in the token, the proxy setting checks or forwards it, and the upstream app receives the result. Confirm each mapper and setting against the OAuth2 Proxy documentation for the version you deploy.
| Keycloak source | OAuth2 Proxy setting that consumes it | Header or decision for the upstream app |
|---|---|---|
| Groups claim (group membership mapper) | --allowed-group and --oidc-groups-claim, checked on each request | Request is allowed or denied at the proxy; group names can be forwarded in the groups header |
| Audience claim (audience mapper) | --oidc-extra-audience and the audience check on the access token | Token is accepted only if it was issued for the expected client, so tokens minted for other clients are refused |
| Email claim (email in ID token) | --email-domain for domain restriction, and the email header | Request is denied for other domains; X-Forwarded-Email carries the address to the app |
| Preferred username claim | --oidc-email-claim or --user-id-claim choice, and the user header | X-Forwarded-User or X-Forwarded-Preferred-Username identifies the signed-in user to the app |
| Realm or client roles (role mapper) | Not read by default; requires a custom mapper or group-based rule | Role-based access must be confirmed in your proxy version before the app relies on it |
| Access token and ID token presence | --pass-access-token and --set-authorization-header | Bearer token is forwarded to the app only if you enable it; confirm the app should receive a Keycloak token at all |
Hardening the proxy, the client secret and the header trust boundary
OAuth2 Proxy sits between users and a tool that trusts whatever identity reaches it, so its security depends on a few controls working together. The cards below cover the client secret, the cookie, the header boundary, group scope and the Keycloak hostname layout. Each one ends in a check your team can run and record.
Store the client secret outside config files
The confidential client secret lets OAuth2 Proxy exchange authorization codes with Keycloak, so anyone who reads it can impersonate the proxy. Load it from your secret store or a Kubernetes Secret rather than a values file in source control, and restrict who can read that secret. Check that the secret is absent from container images, startup logs and ConfigMaps, and plan a rotation procedure that updates both the Keycloak client and the proxy.
Set a strong cookie secret and tight cookie flags
The cookie secret encrypts the session cookie that proves a user is signed in, so its strength determines whether that cookie can be forged. Generate it from a cryptographically secure random source, store it as a secret, and rotate it on a schedule your team sets. Confirm that the cookie is marked secure and HTTP-only, that its domain is limited to the tool's hostname, and that the session lifetime matches your access policy.
Strip client-supplied identity headers
OAuth2 Proxy passes identity to the upstream in headers such as the user and email values, and the upstream usually trusts them without checking. A client can send the same header names directly unless the proxy or ingress removes them first. Configure the proxy to set its own values, strip incoming copies at the edge, and test by sending a forged header through the public route and confirming the upstream still sees the proxy's value.
Make the upstream reachable only through the proxy
A header trust boundary holds only if nothing can reach the tool without passing the proxy. Bind the upstream to a private interface or a network policy that allows traffic only from the proxy, and block direct access from the user network. Verify by connecting to the upstream address from a client subnet and confirming the connection fails. Record the result alongside the ingress rules.
Limit access to the groups that need it
Group and role restrictions decide who reaches the tool at all, so an overly broad group claim becomes an overly broad admin surface. Map each tool to one dedicated Keycloak group, confirm the groups claim only includes groups the proxy needs, and avoid granting access through a default or everyone group. Review group membership on a set schedule and test that a user outside the group receives a denial.
Separate the admin console hostname
Keycloak's production guide advises exposing the admin console and Administration REST API on a different hostname or context path from public frontend URLs. The proxy's redirect and token endpoints should use only the public frontend hostname, so admin paths are not reachable through the same route that serves user sign-in. Verify by requesting the admin path through the public hostname and confirming it is not served.
Keycloak production guideWhere OAuth2 Proxy adds identity headers and enforces group checks
The request starts in the browser, which hits OAuth2 Proxy first. If no session exists, the proxy redirects the browser to Keycloak for sign-in, then receives the authorization code back on its callback and exchanges it for tokens. The proxy checks the groups claim against the allowed groups before it forwards the request, and only then adds identity headers to the upstream call to the internal app. Check that the proxy, not the app, is the only path that can reach the app, because the headers are trusted only inside that boundary.
Sign-in, token exchange, group enforcement and header injection before the app receives a request.
Why sign-in loops, denials and missing headers happen
This table pairs each common OAuth2 Proxy and Keycloak failure with its likely cause and the fix to check first. Read it when a sign-in loops, a valid user gets denied, or an upstream app sees no identity headers. Most of these faults sit in one of three places: the Keycloak client settings, the token claims, or the reverse proxy in front of OAuth2 Proxy.
| Symptom | Likely cause | Fix to check first |
|---|---|---|
| Redirect URI mismatch | The callback URL OAuth2 Proxy sends does not match a valid redirect URI on the Keycloak client, often because the public hostname or scheme differs from the internal one. | Set the valid redirect URI on the confidential client to the exact public https callback path, and set the proxy's redirect URL to match. |
| Missing audience claim | The access token lacks the audience OAuth2 Proxy expects, so the proxy rejects the token even though sign-in succeeded. | Add an audience mapper to the client scope so the expected client ID appears in the token's aud claim, then sign out and sign in again. |
| Missing groups claim | No groups mapper is attached to the client or scope, so the groups claim is absent and group restrictions deny everyone. | Add a group membership mapper with the claim name your allowed-groups setting uses, and confirm the claim in a decoded test token. |
| Cookie domain or secure flag errors | Behind a TLS-terminating reverse proxy, the cookie domain or secure setting does not match the public hostname, so the browser drops the session cookie and the flow restarts. | Set the cookie domain to the parent domain that covers the app, keep the secure flag on, and confirm the proxy forwards the original host and scheme headers. |
| Client secret mismatch | The secret in the proxy configuration differs from the secret stored in Keycloak, or was rotated on one side only, which fails the code exchange. | Regenerate or copy the secret from the Keycloak client credentials tab into the proxy's secret source, then restart the proxy and retest. |
| Valid users denied by group restrictions | The allowed-groups list uses full group paths or names that differ from the claim value, or users belong to a subgroup the rule does not match. | Compare the claim value in a decoded token with the configured group string, and match the format exactly, including any leading slash. |
| Upstream app trusts spoofed headers | The application reads identity headers such as X-Forwarded-User directly, and the client can send the same header to the app when the proxy is bypassed or misrouted. | Make the app reachable only through OAuth2 Proxy with network policy, strip inbound identity headers at the edge, and have the app accept headers only from the proxy address. |
Questions teams ask before fronting a tool with OAuth2 Proxy and Keycloak
How much does it cost to put OAuth2 Proxy in front of an internal tool with Keycloak?
The cost comes from the people doing the work, not from the software, since OAuth2 Proxy and Keycloak are both open source. Your bill has two parts: internal or partner labor to plan, configure, test and hand over the setup, and recurring effort to patch, rotate client secrets and review group mappings. The main cost drivers are the number of tools, how many distinct access groups you need, whether each tool needs its own proxy instance, how your network reaches the tools, and how deeply you test. DeployOpen does not publish prices. Ask any partner for a quote built from a written scope that lists each tool, its group rules, the environments covered and the test evidence you will receive.
How long does it take to add Keycloak login to an internal dashboard with OAuth2 Proxy?
Duration depends on how many tools sit behind the proxy, how well your group model is already defined in Keycloak, and whether the tools use headers the proxy can pass cleanly. A single tool in a lab that already has a Keycloak realm and a working group structure can be set up quickly, while a set of tools that needs new groups, audience mappers and a staged rollout takes longer. No supplied figure gives a fixed duration, so ask any partner to state the duration in the written scope and to list the dependencies that could move it, such as access approvals, DNS changes and certificate issuance.
What does our team need to provide before the work starts?
You need a named Keycloak administrator, a realm to use or create, and an owner for each tool who can confirm what the application expects from identity. Prepare the list of groups or roles that should reach each tool, the hostnames the proxy will use, the network paths from the proxy to each upstream, and where TLS certificates will come from. You also need someone who can approve the header names the tool will trust, because passing identity in headers only works safely when the tool is reachable solely through the proxy. Agree on a test environment before production access is requested.
Can a capable in-house team set up OAuth2 Proxy with Keycloak alone?
Yes, a team that already runs Keycloak and can read the OAuth2 Proxy configuration documentation can usually handle one or two tools without outside help. The work is mostly configuration: creating a confidential client, adding audience and groups mappers so the proxy receives the claims it needs, restricting access by group or role, and passing headers to the upstream. The harder parts are reasoning about trust boundaries, confirming that the tool cannot be reached around the proxy, and writing tests that prove a user outside the allowed groups is refused. Teams with limited Keycloak or security experience often ask for an outside review of those points.
Which parts of this work most often need outside help?
Teams most often ask for help with three areas. The first is the group and role model, because mapping organizational groups into claims that the proxy can enforce consistently is easy to get wrong when tools share a realm. The second is network design, since a tool that stays reachable directly bypasses the proxy and its identity checks. The third is testing, where you need evidence that unauthorized users, expired sessions and direct requests are all blocked. Outside help is also useful when many tools must share one proxy pattern and you want a repeatable configuration that your own team can maintain afterward.
What goes wrong when a tool trusts headers from OAuth2 Proxy?
The most serious failure is that the tool accepts identity headers from any client that can reach it directly, which lets a user forge a username or group. Other common problems include stripping or overwriting incoming headers at the proxy, mismatched claim names so that groups arrive empty, and sessions that outlive a user's removal from a group. Confirm the header names and trusted sources in the proxy and tool documentation, restrict the upstream to the proxy's network path, and test a request that carries forged headers. Recheck these settings after every proxy or Keycloak upgrade.
Does fronting a tool with Keycloak satisfy our access control requirements?
A proxy with Keycloak login enforces authentication and group-based access at the front door, which supports access control requirements, but it does not by itself make your environment compliant. Auditors look for evidence: documented access rules, the group mappings that enforce them, logs of authentication and denied requests, and records of periodic access review. DeployOpen prepares systems, controls and evidence for compliance assessments, but independent auditors and certification bodies issue any audit report or certification. Ask your assessor which control evidence they expect before the design is fixed.
How DeployOpen scopes and delivers this integration
DeployOpen plans and builds the OAuth2 Proxy layer in front of your internal tools inside your own infrastructure, with the Keycloak confidential client, group and audience mappers, and header passing agreed up front. Each engagement is scoped in writing, tested before handover, and documented so your own team can run the proxy after the project ends.
How we scope
- We list each internal dashboard or tool, its hostname, and whether it accepts identity headers or needs a bearer token.
- We agree which Keycloak realm, confidential client, groups and roles will gate each application before any configuration starts.
- Engagements are fixed-scope, with deliverables and timelines agreed in writing before work begins.
How we build
- We configure the Keycloak client, audience and groups mappers, and the OAuth2 Proxy keycloak-oidc provider in your environment.
- We set group and role restrictions and header passing so each upstream app receives only the identity data it needs.
- We test sign-in, sign-out, denied access and header spoofing attempts against each protected application before handover.
How we hand over
- We deliver configuration files, client settings, runbooks and a record of which groups map to which applications.
- We walk your platform and security teams through the proxy setup, token and cookie settings, and the recovery steps.
- We document which Keycloak and OAuth2 Proxy versions were tested so upgrades can be planned against a known baseline.
How we support
- Ongoing support, version upgrades and continuous testing are available as a DeployOpen retainer.
- Retainers can cover reviewing new Keycloak releases and OAuth2 Proxy updates before they reach production.
- Ask any provider to confirm response expectations and upgrade responsibilities in the written quote before signing.

