opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: add OpenRouter OAuth PKCE authentication

Open Void-n-Null opened this issue 3 days ago • 3 comments

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 OpenRouterAuthPlugin in packages/opencode/src/plugin/openrouter.ts
  • Register plugin in INTERNAL_PLUGINS array
  • Add hint text for OpenRouter in provider selection

Implementation

The plugin follows the same pattern as CodexAuthPlugin:

  1. Starts a local HTTP server on port 3000 to receive the OAuth callback
  2. Generates PKCE code verifier and challenge (S256)
  3. Opens browser to OpenRouter authorization URL
  4. Exchanges authorization code for API key via POST to /api/v1/auth/keys
  5. 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

  1. Run opencode auth login
  2. Select OpenRouter
  3. Select "OpenRouter Account"
  4. Browser opens to OpenRouter authorization page
  5. After authorization, callback is received and API key is stored

Void-n-Null avatar Jan 11 '26 08:01 Void-n-Null