opencode
opencode copied to clipboard
feat: add OpenRouter OAuth PKCE authentication
Closes #7766
Summary
Add support for authenticating with OpenRouter using OAuth PKCE flow, allowing users to log in with their OpenRouter account instead of manually entering an API key.
Changes
- Add
OpenRouterAuthPlugininpackages/opencode/src/plugin/openrouter.ts - Register plugin in
INTERNAL_PLUGINSarray - Add hint text for OpenRouter in provider selection
Implementation
The plugin follows the same pattern as CodexAuthPlugin:
- Starts a local HTTP server on port 3000 to receive the OAuth callback
- Generates PKCE code verifier and challenge (S256)
- Opens browser to OpenRouter authorization URL
- Exchanges authorization code for API key via POST to
/api/v1/auth/keys - Stores the key as
type: "api"(OpenRouter returns a permanent API key, not refresh tokens)
Reference: https://openrouter.ai/docs/guides/overview/auth/oauth
Testing
- Run
opencode auth login - Select OpenRouter
- Select "OpenRouter Account"
- Browser opens to OpenRouter authorization page
- After authorization, callback is received and API key is stored