fix: derive OAuth callback URLs from request headers (#333)#334
Merged
Conversation
…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.
radaghastly
approved these changes
Feb 25, 2026
Collaborator
radaghastly
left a comment
There was a problem hiding this comment.
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. 👍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OAuth callback URLs were hardcoded to the static
baseUrlcomputed at startup (defaults tohttp://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:getBaseUrl(req)— derives base URL per-requestBASE_URLenv var >X-Forwarded-Proto/X-Forwarded-Hostheaders >req.protocol/req.headers.host6 OAuth service files (youtube, calendar, fitbit, linkedin, reddit, mastodon):
getBaseUrlfrom shared.jsbaseUrlwithgetBaseUrl(req)in route handlers (setup, callback, retry)renderCardfunctions unchanged (display-only, fine with static URL)How it works
BASE_URLenv is set → uses that (explicit config wins)X-Forwarded-ProtoandX-Forwarded-Hostfrom the proxyreq.protocol/req.headers.hostNo config needed when behind a standard reverse proxy that sets forwarding headers.
Closes #333
Testing