feat: OAuth authentication for AI providers#9
Merged
Conversation
Add foundational types for OAuth authentication: - OAuthTokens, OAuthFlowStatus, AuthMethod types - Discriminated ProviderConfig union (ProviderConfigApiKey | ProviderConfigOAuth) - OAUTH_CAPABILITIES map with endpoints, scopes, PKCE params for OpenAI/Google - OAuthError and OAuthTokenExpiredError classes OpenAI OAuth aligns with official docs: offline_access scope, id_token_add_organizations, codex_cli_simplified_flow params, and token exchange grant support. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
New OAuthService handles complete OAuth authentication: - PKCE flow with loopback HTTP server on random port - S256 code challenge method per RFC 7636 - OpenAI token exchange (ID token → API key via token-exchange grant) - Automatic token refresh scheduling (5 min before expiry) - XSS-safe callback HTML with proper escaping SettingsService extended with OAuth token CRUD: - getOAuthTokens, setOAuthTokens, deleteOAuthTokens - getAuthMethod, setAuthMethod - Encrypted storage via safeStorage - Backward-compatible with existing settings files Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Adapters support dual authentication: - OpenAIAdapter: API key OR OAuth token with chatgpt-account-id header - GoogleAdapter: API key (x-goog-api-key) OR OAuth Bearer token - ProviderManager: handles discriminated config union, updateOAuthToken() New oauth.router with tRPC procedures: - startFlow, disconnect, getStatus, getCapabilities IPC layer updates: - Context instantiates OAuthService, restores OAuth on startup - Expired tokens refreshed immediately before provider configuration - Token refresh callback wired for automatic updates - Preload bridge exposes onOAuthStatus/removeOAuthListeners Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
New ProviderCard component: - OAuth sign-in button for supported providers (OpenAI, Google) - "Experimental" badge for unstable providers - Connected state shows email with disconnect button - API key notice for Anthropic (OAuth not supported) Redesigned SettingsDialog: - Provider cards with OAuth as primary auth method - Collapsible "Advanced: Use API Keys" section - OAuth status listener for real-time flow updates settingsStore extended with OAuth state: - oauthStatus per provider (connected, email, authMethod) - oauthFlowStatus (idle, pending, success, error) - startOAuthFlow, disconnectOAuth, updateOAuthFlowStatus actions Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
OpenAI OAuth requires specific redirect configuration: - Fixed port 1455 (not random) - Callback path /auth/callback (not /callback) - localhost hostname (not 127.0.0.1) Added redirectPort and callbackPath to OAUTH_CAPABILITIES. Updated OAuthService to use provider-specific settings. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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
Replace API key inputs as the primary auth method with OAuth sign-in buttons. Users authenticate with their existing AI provider subscriptions instead of paying per-token API pricing.
Provider Support
auth.openai.com. Uses ChatGPT Plus/Pro subscription.Changes
New Files
src/main/services/OAuthService.ts- PKCE flow, loopback server, token exchange, refreshsrc/main/ipc/oauth.router.ts- tRPC routes: startFlow, disconnect, getStatus, getCapabilitiessrc/renderer/features/settings/ProviderCard.tsx- Per-provider card with OAuth buttonKey Features
Technical Details
offline_accessscope,id_token_add_organizations,codex_cli_simplified_flowparamsTest Plan
🤖 Generated with Claude Code