oauth2-proxy: Bolting SSO Onto an App That Never Asked for It
A full identity provider is overkill for putting one login screen in front of one app that was never built to have one

Contents
I’ve written before about running Authentik as the central identity provider for a homelab, and about weighing Authelia against it for that same job. Both are genuinely full identity platforms — user directories, multiple protocol support, admin UIs, the works. What neither post addressed is the much smaller, more common problem that shows up constantly once an identity provider exists: some self-hosted app on the network has no authentication of its own at all, or has auth so weak it’s barely worth calling that, and it needs something in front of it before it’s reachable from anywhere but localhost. Building that app’s own OAuth integration is usually not an option — it’s someone else’s code, or it’s a tool that was never designed with SSO in mind. oauth2-proxy solves that specific case: a small reverse-proxy sidecar that sits in front of any HTTP application, handles the entire OAuth/OIDC login flow itself, and only lets a request through to the app once that flow has succeeded. The app behind it never sees a login form, never handles a token, and often never even knows authentication was added.
Where it sits in the request path
oauth2-proxy is a proxy in the literal sense — it terminates the incoming HTTP request, and either serves a redirect to the identity provider’s login page (if there’s no valid session yet) or forwards the request through to the real backend application (if there is). This is usually deployed as a small extra hop behind an existing reverse proxy like Traefik or nginx, using Traefik’s own middleware chain to route unauthenticated requests to oauth2-proxy first and only pass them on to the real backend after it approves them:
| |
Once a session is established, oauth2-proxy sets its own signed cookie, and subsequent requests pass through quickly with only a cookie validation — no fresh round-trip to the identity provider required on every single page load.

Setting it up against an existing identity provider
oauth2-proxy speaks standard OAuth2/OIDC, so it works against Authentik, Authelia, Google, GitHub, or any other compliant provider — the setup is registering oauth2-proxy as a client application in whichever provider you already run, then pointing oauth2-proxy at that client’s credentials:
| |
That upstreams line is the whole trick — it’s the address of the real application, entirely unaware of anything happening in front of it. As far as the backend is concerned, it’s just receiving normal HTTP requests from something on its own network; oauth2-proxy is the only component that ever talks to the identity provider or handles a token.
| |
Passing identity through to an app that can use it
Some backend apps, even ones with no auth of their own, can still make use of who is logged in if they’re told — for a per-user audit log, a personalised view, or simple access logging. oauth2-proxy supports this via response headers, forwarding the authenticated user’s identity to the backend on every request that gets through:
| |
An application that trusts these headers has to actually be deployed so it can only be reached through oauth2-proxy — if the backend is directly reachable on the network without going through the proxy, anyone with network access can forge those headers and impersonate any user, since the backend has no independent way to verify they came from a real authenticated session. This is the single most important deployment detail and the one that’s easiest to get wrong: the backend port has to be genuinely firewalled off from everything except the proxy, rather than merely left unadvertised on the network.
The nginx auth_request pattern, for apps that don’t sit fully behind the proxy
Not every setup wants oauth2-proxy directly in the request path for the application’s own traffic — sometimes it’s cleaner to let the existing reverse proxy handle the app directly and only consult oauth2-proxy as a yes/no gate. nginx’s auth_request directive does exactly that:
| |
Here, nginx asks oauth2-proxy a lightweight “is this request authenticated” question via a subrequest before ever proxying to the real backend, rather than routing the actual application traffic through oauth2-proxy as a full hop. Functionally the two patterns end at the same place — the app is unreachable without a valid session — but the auth_request pattern keeps the bulk of application traffic on the existing proxy’s direct path, which matters more for high-traffic apps where the extra hop through oauth2-proxy for every single request would add latency worth avoiding.
Restricting access beyond a valid login
A valid login from the identity provider isn’t automatically the same thing as “this specific person should have access to this specific app” — oauth2-proxy supports restricting access further, by email domain, specific email address, or (against providers that support it) group membership claims from the token itself:
| |
For anything sensitive, group-based restriction sourced from the identity provider itself is the more maintainable approach long-term — adding or removing someone’s access becomes a group membership change in the identity provider rather than an oauth2-proxy config edit and restart, which matters once more than one app is using the same oauth2-proxy pattern across a homelab. oauth2-proxy also supports a lightweight skip-auth-route option for endpoints that genuinely need to stay public even behind an otherwise gated app — a health check endpoint a monitoring system needs to poll without going through a login flow, for instance — configured as an explicit exception rather than something achieved by disabling the gate more broadly than intended:
| |
Keeping that exception list short and specific matters, since every route added to it is a route the proxy no longer protects at all, and a health-check exception written too broadly (a prefix match intended for one endpoint that accidentally matches a whole path tree) is a quiet way to leave more of an app open than intended.
Sharing one login across several apps
The single-app example above is the simplest case, but the more common homelab shape is several apps, each needing the same gate, without asking a user to log in separately for every one of them. Setting the session cookie’s domain to the parent domain rather than the individual subdomain is what makes this work — a login on one app’s oauth2-proxy instance produces a cookie the browser will also send to every other subdomain under the same parent, so a second app’s oauth2-proxy instance sees an already-valid session and skips the login redirect entirely:
| |
Each app still runs its own oauth2-proxy instance (or shares one central instance handling multiple upstreams, depending on deployment preference), but because they all trust cookies scoped to the same parent domain and the same cookie_secret, one authentication event at the identity provider covers every app behind the pattern — genuine single sign-on across a homelab’s whole collection of otherwise auth-less tools, rather than a separate login per app.
oauth2-proxy vs Authelia’s built-in forward-auth
Authelia ships its own forward-auth endpoint that does conceptually the same job oauth2-proxy does — sitting in front of an app via the reverse proxy and gating access based on an existing session — which raises the obvious question of why reach for a separate tool at all when an identity platform already covers this. The practical difference is scope and coupling: Authelia’s forward-auth is tightly integrated with Authelia’s own session and policy engine, which is the right choice if Authelia is already the identity provider in use and its access-control-list-based policy model (path-based rules, per-group restrictions defined centrally in Authelia’s own config) covers what’s needed. oauth2-proxy, by contrast, works against any OIDC-compliant provider — Authentik, Authelia itself, Google Workspace, a generic Keycloak instance — which matters if the identity provider might change over time, if different apps in the same environment need to authenticate against different providers, or simply if the provider in use doesn’t ship its own forward-auth equivalent at all. Running Authelia already and needing nothing beyond what its forward-auth provides is a reasonable case for skipping oauth2-proxy entirely; needing a provider-agnostic gate, or already committed to a provider without built-in forward-auth support, is the case oauth2-proxy fits.
Troubleshooting
A redirect loop between the app and the login page. This almost always traces back to the cookie domain or the redirect_url not matching the actual URL the app is reached at — a mismatch between what’s configured and what’s in the browser’s address bar means the cookie set after login never gets sent back on the next request, so oauth2-proxy thinks the session never happened and redirects to login again.
Login succeeds but the backend app still shows its own “not logged in” state. Check whether the app was actually built to read the X-Auth-Request-* headers oauth2-proxy forwards — many apps simply have no concept of receiving identity this way, and for those, oauth2-proxy is providing access control (can this person reach the app at all) rather than genuine single sign-on (the app itself recognising who’s logged in), which is a real distinction worth setting expectations around before deploying it.
Someone who left the identity provider’s allowed group can still get in. Check whether oauth2-proxy is validating group membership on every request or only at initial login — depending on configuration and cookie lifetime, a session established before a group change can remain valid until it expires rather than being revoked immediately, which matters for anything where prompt access revocation is a real requirement rather than a nice-to-have.
The backend app is reachable directly, bypassing oauth2-proxy entirely. This is a firewall or network segmentation gap rather than an oauth2-proxy misconfiguration — the fix is making sure the backend’s port is genuinely unreachable except from the proxy: a Docker network with no published port, a host firewall rule, or VLAN segmentation, something enforced by the network itself, unlike a documentation note saying “please go through the proxy.”
Where this fits next to a full identity platform
oauth2-proxy isn’t a replacement for Authentik or Authelia — it doesn’t manage users, doesn’t have its own directory, and doesn’t do anything without an existing OIDC provider behind it to actually authenticate against. It’s the piece that sits between a full identity platform and an application that was never built to speak OAuth itself, which is most self-hosted homelab software. If you already run an identity provider and keep hitting apps with no login of their own, oauth2-proxy is the small, boring, single-purpose tool that closes that gap without asking the app’s own code to change at all. It’s also worth pairing with, rather than treated as a substitute for, sensible network-level restriction — VLAN segmentation keeping the app reachable only from trusted network segments in the first place, and a docker-socket-proxy-style discipline of exposing the smallest possible surface generally. oauth2-proxy answers “who is this” — a separate question from “should this even be reachable from here” — and a homelab that treats those as the same question tends to end up with one login screen protecting an otherwise wide-open network.




