Skip to content

fix: derive OAuth callback URLs from request headers (#333)#334

Merged
monteslu merged 1 commit into
mainfrom
fix/oauth-callback-base-url
Feb 25, 2026
Merged

fix: derive OAuth callback URLs from request headers (#333)#334
monteslu merged 1 commit into
mainfrom
fix/oauth-callback-base-url

Conversation

@luthien-m
Copy link
Copy Markdown
Collaborator

Summary

OAuth callback URLs were hardcoded to the static baseUrl computed at startup (defaults to http://localhost:3050). When AgentGate runs behind a reverse proxy, Google/Fitbit/etc redirect to localhost instead of the real server.

Changes

src/routes/ui/shared.js:

  • Added getBaseUrl(req) — derives base URL per-request
  • Priority: BASE_URL env var > X-Forwarded-Proto/X-Forwarded-Host headers > req.protocol/req.headers.host

6 OAuth service files (youtube, calendar, fitbit, linkedin, reddit, mastodon):

  • Import getBaseUrl from shared.js
  • Replace closure baseUrl with getBaseUrl(req) in route handlers (setup, callback, retry)
  • renderCard functions unchanged (display-only, fine with static URL)

How it works

  1. If BASE_URL env is set → uses that (explicit config wins)
  2. Otherwise reads X-Forwarded-Proto and X-Forwarded-Host from the proxy
  3. Falls back to req.protocol/req.headers.host

No config needed when behind a standard reverse proxy that sets forwarding headers.

Closes #333

Testing

  • ✅ ESLint: 0 errors
  • ✅ All 99 tests pass (8 suites)

…oded baseUrl

When AgentGate runs behind a reverse proxy, OAuth callbacks were
hardcoded to http://localhost:3050. Now uses getBaseUrl(req) which
checks BASE_URL env > X-Forwarded-Proto/Host headers > req fallback.

Updated all 6 OAuth service files: youtube, calendar, fitbit,
linkedin, reddit, mastodon.
Copy link
Copy Markdown
Collaborator

@radaghastly radaghastly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Clean approach — getBaseUrl(req) with the right priority (env > forwarded headers > request). Consistent change across all 6 OAuth services. _baseUrl prefix to avoid lint unused-var is a nice touch. 👍

@monteslu monteslu merged commit 7ffece9 into main Feb 25, 2026
3 checks passed
@monteslu monteslu deleted the fix/oauth-callback-base-url branch February 25, 2026 03:25
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.

Bug: OAuth callback URL hardcoded to localhost:3050

3 participants