fix(oauth): translate first-party client_id when switching region#58031
Closed
Twixes wants to merge 1 commit into
Closed
fix(oauth): translate first-party client_id when switching region#58031Twixes wants to merge 1 commit into
Twixes wants to merge 1 commit into
Conversation
When a user is mid-OAuth on /login?next=/oauth/authorize?client_id=... and uses RegionSelect to switch from US to EU (or vice versa), the existing code rewrote only the host. The embedded client_id stayed region-specific, so the destination server rejected the flow with "Invalid client_id" — most visibly hurting EU customers who installed PostHog Code (which defaults to US) and tried to switch on the web. Add a small frontend mapping of well-known cross-region first-party client_ids (currently PostHog Code) and rewrite the client_id inside both /oauth/authorize directly and /login?next=/oauth/authorize?... when the region changes. Unknown / third-party client_ids pass through unchanged. Generated-By: PostHog Code Task-Id: d739b1d2-b053-45ec-967b-5521802d275b
Contributor
|
🎭 Playwright didn't run on this PR — your changes touch code that could affect E2E behavior, but Playwright is opt-in via label now to keep CI cost down. Add the Most PRs don't need this. Real regressions still get caught on master and fix-forward. |
Contributor
|
Size Change: -127 B (0%) Total Size: 112 MB 📦 View Changed
ℹ️ View Unchanged
|
Contributor
|
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, please remove the |
Contributor
|
This PR was closed due to lack of activity. Feel free to reopen if it's still relevant. |
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
When a user is on `/login?next=/oauth/authorize?client_id=...` (the typical chain hit by an EU customer who installed PostHog Code with its US default and clicked "Sign in"), the existing `` swapped the host but kept the embedded `client_id` unchanged. Because first-party OAuth applications are registered with different `client_id`s on each regional Cloud instance, the destination server returned "Invalid client_id" and the flow died on a confusing error page. This is the broken EU switch reported by users.
This PR introduces `crossRegionOAuth.ts`, a small frontend mapping of well-known cross-region first-party `client_id`s (currently PostHog Code), and uses it from `RegionSelect.tsx` when the user changes region. We rewrite the `client_id` for both:
Unknown / third-party `client_id`s pass through unchanged, so the failure mode for non-first-party clients is identical to today.
The mapping intentionally lives in a small, well-commented module; it must stay in sync with `posthog/temporal/oauth.py` (`ARRAY_APP_CLIENT_ID_*`), `apps/code/src/shared/constants/oauth.ts` in PostHog Code, and the OAuth proxy KV at `oauth.posthog.com`. Future first-party apps just append a new entry.
Companion UI prominence improvement in PostHog Code: PostHog/code#2090
Caveats / things to verify
Test plan
Created with PostHog Code