Skip to content

fix(oauth): force project selection screen on every login#487

Draft
gewenyu99 wants to merge 1 commit into
mainfrom
posthog-code/oauth-force-project-selection
Draft

fix(oauth): force project selection screen on every login#487
gewenyu99 wants to merge 1 commit into
mainfrom
posthog-code/oauth-force-project-selection

Conversation

@gewenyu99
Copy link
Copy Markdown
Collaborator

Problem

Users running npx @posthog/wizard who have already authorized the wizard in their browser sometimes never see the OAuth scope authorization / project picker screen on subsequent runs. The wizard silently picks up the previously-authorized project from the OAuth token response and ends up "mangling" an unrelated existing project instead of letting the user pick or create the right one.

Reported on Slack by Michael Matloka and reproduced intermittently by Edwin.

Root cause: the wizard constructs the OAuth authorize URL with required_access_level=project but no approval_prompt. Django OAuth Toolkit (which powers PostHog's OAuth server) defaults to approval_prompt=auto, which short-circuits the authorization screen when a valid prior consent exists. On a silent re-consent, the server hands back a token scoped to the user's previously-selected project; in setup-utils.ts the wizard reads tokenResponse.scoped_teams?.[0] without any further confirmation, so the wrong project gets wired up.

Changes

Pass approval_prompt=force on the OAuth authorize URL in src/utils/oauth.ts so the PostHog authorization server always renders the project authorization screen, even when the browser still has an active PostHog session and a prior consent on file.

Test plan

  • Run pnpm try --install-dir=<path> after having previously completed an OAuth login (cookie still warm) and confirm the project picker is shown.
  • Run twice in a row against the same browser; the second run should still show the picker.
  • Verify US and EU regions both hit the picker.
  • Existing first-time OAuth flow continues to work end-to-end.

Created with PostHog Code

Pass `approval_prompt=force` on the OAuth authorize URL so the PostHog
authorization server always renders the scope/project authorization
screen, even when the user's browser still has an active session from
a previous wizard run.

Without this, the OAuth server can silently re-consent using the user's
previously-authorized project — `scoped_teams[0]` then resolves to the
old project and the wizard instruments the wrong codebase against it.
Forcing the approval screen restores the project picker so users can
intentionally select or create the project for this install.

Generated-By: PostHog Code
Task-Id: fd37c61b-0f0d-42d3-ba41-bc8e2a4bfdca
@github-actions
Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci basic-integration
  • /wizard-ci misc
  • /wizard-ci revenue

Test an individual app:

  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
Show more apps
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci misc/quack-quack
  • /wizard-ci revenue/stripe

Results will be posted here when complete.

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