A failed login at 2 a.m. lit up every alert you own. The app was fine. The load balancer was not.
If you run OpenID Connect (OIDC) behind an external load balancer, you already know the stakes. Misconfigure it, and tokens fail to validate. Configure it right, and users glide through authentication without noticing the infrastructure that makes it possible. The trouble is, OIDC is not just another HTTP service. It’s stateful where load balancers prefer stateless. It leans on redirects that don’t play nice with lazy routing. And it depends on strict security rules that break when network layers get clever.
An external load balancer must handle four things for OIDC to work without pain:
- Sticky sessions. OIDC uses the
stateparameter to track auth flows. Without session affinity, users bounce between nodes mid-flow, losing that state and triggering failures. - HTTPS termination. TLS must be terminated in a way that preserves headers like
X-Forwarded-Protoand exact redirect URIs. Even one mismatch breaks the handshake with your Identity Provider (IdP). - WebSocket or long-polling readiness. Many modern OIDC-based apps use silent token refresh or backchannel connections. Your load balancer has to pass them as-is.
- Correct idle timeout settings. Long-lived OIDC sessions die abruptly if the load balancer closes connections too soon.
The most common cause of OIDC issues with an external load balancer is subtle mismatch between what your IdP expects and what your load balancer does by default. This includes incorrect forwarding of host headers, failing to preserve query strings, and redirect rewrites that silently break OAuth2 flows.