Skip to content

fix: use server-side KEYCLOAK_URL for Docker JWT verification#554

Open
Rashmil-1999 wants to merge 3 commits intomainfrom
fix/keycloak-server-side-url
Open

fix: use server-side KEYCLOAK_URL for Docker JWT verification#554
Rashmil-1999 wants to merge 3 commits intomainfrom
fix/keycloak-server-side-url

Conversation

@Rashmil-1999
Copy link
Contributor

@Rashmil-1999 Rashmil-1999 commented Feb 17, 2026

Summary

  • Server-side middleware was using NEXT_PUBLIC_KEYCLOAK_URL (http://localhost:8080) for JWT verification, which resolves to the frontend container itself in Docker — causing ECONNREFUSED
  • getKeycloakBaseFromHost() now checks the runtime KEYCLOAK_URL env var first when running server-side, enabling proper container-to-container communication via Docker DNS (http://keycloak:8080)
  • Separated JWKS key fetching URL (internal KEYCLOAK_URL) from JWT issuer verification URL (public-facing, matching Keycloak's --hostname setting) to fix jwt issuer invalid errors
  • Added getKeycloakIssuerBaseUrl() helper and updated createTokenVerifier / verifyTokenAsync to accept a separate issuer URL
  • Client-side behavior is unchanged — browsers still use the build-time NEXT_PUBLIC_KEYCLOAK_URL

Test plan

  • Rebuild frontend container (docker compose build frontend)
  • Verify JWT verification succeeds (no more ECONNREFUSED or jwt issuer invalid in middleware logs)
  • Verify browser-side Keycloak login still redirects correctly

…fication

In Docker, the frontend container's middleware resolves NEXT_PUBLIC_KEYCLOAK_URL
(http://localhost:8080) to itself instead of the keycloak container, causing
ECONNREFUSED. Prefer the runtime KEYCLOAK_URL env var (http://keycloak:8080)
on the server side for proper Docker DNS resolution.
@vercel
Copy link

vercel bot commented Feb 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
uiuc-chat-frontend Ready Ready Preview, Comment Feb 17, 2026 3:50am

Request Review

The internal Docker URL (keycloak:8080) is needed for JWKS key fetching
but the issuer claim in JWTs uses Keycloak's public hostname (localhost:8080).
Split these concerns so JWKS uses KEYCLOAK_URL and issuer verification
uses the public-facing URL matching Keycloak's --hostname setting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant