opencode
opencode copied to clipboard
[FEATURE]: Add Gemini CLI OAuth login flow integration
Feature hasn't been suggested before.
- [x] I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
Summary
Add support for authenticating with Gemini using the same OAuth login flow as the official Gemini CLI. This
enables users to authenticate with their Google account directly, matching the experience provided by
gemini-cli.
Problem
Currently, Gemini authentication in OpenCode requires manual API key configuration. The official Gemini CLI
uses an OAuth flow that provides a smoother user experience with browser-based Google account login.
Proposed Solution
Integrate the Gemini CLI OAuth flow into OpenCode's plugin system:
- Implement PKCE-based OAuth flow for secure authentication
- Handle token exchange and refresh automatically
- Cache access tokens with proper expiry handling
- Support both interactive (browser) and headless authentication modes
- Manage GCP project context for API requests
Implementation
The implementation adds a new gemini plugin under packages/opencode/src/plugin/gemini/ with:
-
oauth.ts- OAuth authorization and token exchange -
token.ts- Token refresh logic -
cache.ts- Access token caching -
auth.ts- Auth state helpers -
project.ts- GCP project management -
request.ts/request-helpers.ts- Authenticated API requests -
server.ts- Local callback server for OAuth redirect -
index.ts- Plugin entry point
Verification
- Test OAuth flow in browser-enabled environment
- Test token refresh after expiry
- Verify API requests work with obtained credentials