Skip to content

Add OpenAI OAuth login and Codex Responses API provider - #51

Merged
gburachas merged 1 commit into
mainfrom
feat/openai-oauth-codex
Feb 23, 2026
Merged

gburachas merged 1 commit into
mainfrom
feat/openai-oauth-codex

Conversation

@gburachas

Copy link
Copy Markdown
Owner

Summary

  • OpenAI OAuth flow: PKCE authorization code flow ported from OpenClaw's openai-codex-oauth.ts. Opens browser to auth.openai.com, captures callback on localhost:1455, exchanges code for tokens. Supports manual URL paste for SSH/headless.
  • Codex Responses API provider: Uses chatgpt.com/backend-api/codex/responses with Bearer token + chatgpt-account-id header. Converts messages to Responses API format. Friendly ChatGPT usage limit error messages.
  • Credential storage: Secure JSON storage at ~/.pytoclaw/credentials.json (0600 perms). Supports API key and OAuth credential types with auto-refresh.
  • Onboarding: OpenAI users choose browser_login (default) or api_key. OAuth tokens stored separately from config.yaml.

Key constants (from OpenClaw)

  • Client ID: app_EMoamEEZ73f0CkXaXp7hrann
  • Auth URL: https://auth.openai.com/oauth/authorize
  • Token URL: https://auth.openai.com/oauth/token
  • Redirect: http://localhost:1455/auth/callback
  • API Base: https://chatgpt.com/backend-api

Test plan

  • 94 tests pass (20 new auth tests)
  • Run pytoclaw onboard → select browser_login → complete OAuth in browser
  • Verify ~/.pytoclaw/credentials.json created with OAuth tokens
  • Run pytoclaw agent → verify Codex provider is used

Fixes #50

🤖 Generated with Claude Code

Port OpenAI Codex OAuth flow from OpenClaw. Enables ChatGPT Pro/Plus
users to authenticate via browser instead of API keys, using their
subscription (separate billing from API).

OAuth flow:
- PKCE authorization code flow with localhost:1455 callback
- Browser auto-launch with manual URL paste fallback
- JWT token decoding to extract chatgpt_account_id
- Token refresh support
- Secure credential storage (~/.pytoclaw/credentials.json, 0600)

Codex Responses API provider:
- Uses https://chatgpt.com/backend-api/codex/responses endpoint
- Bearer token + account-id headers
- Converts between internal message format and Responses API format
- ChatGPT usage limit friendly error messages

Onboarding updated:
- OpenAI auth method choice: browser_login (default) or api_key
- OAuth credentials stored securely, not in config.yaml
- Factory auto-detects OAuth credentials for Codex provider

20 new tests (94 total passing).

Fixes #50

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gburachas
gburachas merged commit 818caf2 into main Feb 23, 2026
0 of 2 checks passed
@gburachas
gburachas deleted the feat/openai-oauth-codex branch February 23, 2026 02:54
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.

Onboarding should support OAuth/browser-based authentication, not just API keys

1 participant