Skip to content

feat(auth): add OAuth authorization code + PKCE for Codex provider#2790

Merged
amitksingh1490 merged 14 commits intoantinomyhq:mainfrom
tivris:fix/codex-oauth-login
Apr 4, 2026
Merged

feat(auth): add OAuth authorization code + PKCE for Codex provider#2790
amitksingh1490 merged 14 commits intoantinomyhq:mainfrom
tivris:fix/codex-oauth-login

Conversation

@tivris
Copy link
Copy Markdown
Contributor

@tivris tivris commented Apr 2, 2026

Summary

  • Adds OAuth Authorization Code + PKCE as the primary Codex login method, so non-admin users on OpenAI Business/Enterprise plans can authenticate without requiring workspace admin to enable device code auth
  • Implements a localhost TCP callback server (port 1455) with state validation, 5-minute timeout, and graceful fallback to manual code paste if the port is unavailable
  • Extracts chatgpt_account_id JWT helper to module level so both the new code flow and existing device flow can enrich credentials with the account ID needed for API request headers

Test plan

  • Tested login via forge provider login codex on an OpenAI Business plan account — browser redirect completes without device code prompt
  • Verified API requests work after login (conversation round-trip)
  • cargo test -p forge_main --lib -- ui::tests — 3 tests pass (redirect URI detection, callback capture, state mismatch rejection)
  • cargo test -p forge_infra --lib — 60 tests pass (including extract_chatgpt_account_id tests)
  • cargo clippy -p forge_main -p forge_infra -p forge_repo -- -D warnings — zero warnings
  • Verify device code flow still works as fallback when selected from the auth method prompt

Closes #2767

The Codex provider previously only supported the device code flow,
which requires workspace admin enablement on OpenAI Business/Enterprise
plans. Add authorization code + PKCE as the primary login method so
non-admin users can authenticate through a standard browser redirect.

Provider config (provider.json):
- Add oauth_code entry before codex_device with PKCE, localhost
  redirect on port 1455, and the same client ID / scopes

Auth strategy (strategy.rs):
- Extract chatgpt_account_id helper to module level so both
  OAuthCodeStrategy and CodexDeviceStrategy can use it
- Enrich OAuth code credentials with the ChatGPT account ID
  needed for API request headers

UI callback server (ui.rs):
- Localhost TCP listener with state validation, HTML response
  pages, 5-minute timeout, and graceful fallback to manual paste
  if the port is unavailable

Closes antinomyhq#2767
@github-actions github-actions bot added the type: feature Brand new functionality, features, pages, workflows, endpoints, etc. label Apr 2, 2026
tivris and others added 11 commits April 2, 2026 12:45
Track elapsed time from the start of each accept attempt instead of
comparing a fixed duration against the deadline on every poll iteration.
Prefer id_token claims for ChatGPT account ID extraction and fall back to access_token when needed.

Co-Authored-By: ForgeCode <noreply@forgecode.dev>
Move the localhost OAuth callback server into a dedicated module so ui.rs only orchestrates the browser auth flow.

Co-Authored-By: ForgeCode <noreply@forgecode.dev>
Use the OAuth callback server with a fully qualified path so the UI file keeps fewer incidental changes.

Co-Authored-By: ForgeCode <noreply@forgecode.dev>
Keep the existing placeholder test module in ui.rs so the refactor does not remove unrelated test scaffolding.

Co-Authored-By: ForgeCode <noreply@forgecode.dev>
@amitksingh1490 amitksingh1490 enabled auto-merge (squash) April 4, 2026 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature Brand new functionality, features, pages, workflows, endpoints, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Improve Codex login flow (avoid mandatory device code auth for workspace users)

2 participants