{"id":50230530,"url":"https://github.com/vymalo/opencode-oauth2","last_synced_at":"2026-05-26T18:34:30.343Z","repository":{"id":359950661,"uuid":"1248120411","full_name":"vymalo/opencode-oauth2","owner":"vymalo","description":"OpenCode plugin that secures OpenAI-compatible model providers with OAuth2/OIDC (Authorization Code + PKCE), auto-discovers and syncs models from /v1/models, and injects bearer tokens per request — with strict refresh-token enforcement.","archived":false,"fork":false,"pushed_at":"2026-05-25T01:33:03.000Z","size":273,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-25T01:34:09.409Z","etag":null,"topics":["ai","authorization-code-flow","bearer-token","llm","model-sync","oauth2","oidc","openai-compatible","opencode","opencode-plugin","pkce","plugin","pnpm-workspace","refresh-token","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vymalo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-24T07:59:52.000Z","updated_at":"2026-05-25T01:32:48.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/vymalo/opencode-oauth2","commit_stats":null,"previous_names":["adorsys-gis/opencode-oauth2","vymalo/opencode-oauth2"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/vymalo/opencode-oauth2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vymalo%2Fopencode-oauth2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vymalo%2Fopencode-oauth2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vymalo%2Fopencode-oauth2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vymalo%2Fopencode-oauth2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vymalo","download_url":"https://codeload.github.com/vymalo/opencode-oauth2/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vymalo%2Fopencode-oauth2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33534563,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"ssl_error","status_checked_at":"2026-05-26T15:22:15.568Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","authorization-code-flow","bearer-token","llm","model-sync","oauth2","oidc","openai-compatible","opencode","opencode-plugin","pkce","plugin","pnpm-workspace","refresh-token","typescript"],"created_at":"2026-05-26T18:34:27.162Z","updated_at":"2026-05-26T18:34:30.335Z","avatar_url":"https://github.com/vymalo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# opencode-oauth2\n\n\u003e Bring your own OAuth-protected LLM gateway to [OpenCode](https://opencode.ai).\n\nAn [OpenCode](https://opencode.ai) plugin that lets you wire up **OpenAI-compatible model providers sitting behind OAuth2 / OIDC** — without baking long-lived API keys into your config. Discover models dynamically, refresh tokens automatically, and let OpenCode talk to your gateway as if it were any other provider.\n\n![status: early](https://img.shields.io/badge/status-early-orange)\n![node: \u003e=20](https://img.shields.io/badge/node-%3E%3D20-339933)\n![license: MIT](https://img.shields.io/badge/license-MIT-blue)\n![pnpm workspace](https://img.shields.io/badge/pnpm-workspace-F69220)\n\n---\n\n```mermaid\nflowchart LR\n    OC[opencode] --\u003e|chat.headers| Plugin[opencode-oauth2]\n    Plugin --\u003e|cached token?| Cache[(~/.cache/opencode-oauth2)]\n    Plugin --\u003e|acquire / refresh| IdP[OAuth server]\n    Plugin --\u003e|Authorization: Bearer …| Upstream[Provider API]\n```\n\n## Why\n\nMost OpenCode providers assume a static bearer key. That works for hosted SaaS, but breaks down the moment you put your models behind:\n\n- a corporate Identity Provider (Keycloak, Auth0, Okta, Azure AD, …)\n- a self-hosted gateway with short-lived tokens\n- a multi-tenant setup where each user authenticates as themselves\n- a CI runner that has no business carrying a long-lived secret\n\nThis plugin closes that gap. It handles the OAuth dance for the flow you need, caches tokens, refreshes silently, and feeds OpenCode a normal-looking provider with a fresh `Authorization` header on every request.\n\n## Features\n\n- **Five auth flows**, pick what matches your runtime:\n  - `authorization_code` — interactive PKCE login (default)\n  - `device_code` — RFC 8628, for browserless user auth\n  - `client_credentials` — machine-to-machine with a `clientSecret`\n  - `jwt_bearer` — RFC 7523 federated identity (GitHub Actions OIDC, Kubernetes SA tokens) — **no long-lived secret in CI**\n  - `token_exchange` — RFC 8693 federated identity with explicit audience targeting\n- **Dynamic model discovery** from `/v1/models` (no hand-maintained model lists)\n- **Display-name normalization** so `glm-5` shows up as `GLM 5`\n- **Persistent token cache** with automatic refresh\n- **`chat.headers` hook** injects bearer tokens per request\n- **Two configuration styles**: per-provider options or a top-level plugin block\n\n## Install\n\n```jsonc\n{\n  \"$schema\": \"https://opencode.ai/config.json\",\n  \"plugin\": [\"@vymalo/opencode-oauth2\"]\n}\n```\n\nThen declare a provider:\n\n```jsonc\n{\n  \"plugin\": [\"@vymalo/opencode-oauth2\"],\n  \"provider\": {\n    \"example-ai\": {\n      \"name\": \"Example AI\",\n      \"options\": {\n        \"baseURL\": \"https://api.example.com/v1\",\n        \"oauth2\": {\n          \"issuer\": \"https://auth.example.com\",\n          \"clientId\": \"opencode-client\",\n          \"scopes\": [\"openid\", \"profile\", \"offline_access\"],\n          \"syncIntervalMinutes\": 60\n        }\n      }\n    }\n  }\n}\n```\n\nSee [packages/opencode-oauth2/README.md](packages/opencode-oauth2/README.md) for the **full configuration reference** (including the alternative `pluginConfig.oauth2ModelSync.servers` layout and every optional field).\n\n## Documentation\n\n| Page | When you need it |\n| --- | --- |\n| [`docs/architecture.md`](docs/architecture.md) | Understand the hooks, token lifecycle per flow, cache layout, sync scheduler, logging |\n| [`docs/github-actions.md`](docs/github-actions.md) | CI without stored secrets — Keycloak/Auth0/Okta setup, reusable workflow, matrix, fork-PR limits |\n| [`docs/kubernetes.md`](docs/kubernetes.md) | `CronJob` / `Job` / `Deployment` with projected SA tokens, multi-provider pods, RBAC |\n| [`docs/local-development.md`](docs/local-development.md) | Sandbox setup, plugin re-export trick, forcing re-auth, dev-only `env` subject token |\n| [`docs/troubleshooting.md`](docs/troubleshooting.md) | Symptom-keyed fixes — `redirect_uri_mismatch`, model discovery 403, `invalid_client`, projected-token rotation |\n\n## Federated identity (CI / Kubernetes)\n\nFor GitHub Actions and Kubernetes workloads, use `jwt_bearer` (or `token_exchange`) with the platform's own short-lived OIDC token as the subject. The plugin re-fetches it on every access-token expiry; nothing long-lived gets cached.\n\nEnd-to-end recipes live in [`docs/github-actions.md`](docs/github-actions.md) and [`docs/kubernetes.md`](docs/kubernetes.md). The shipped reusable workflow at [`.github/workflows/opencode-run.yml`](.github/workflows/opencode-run.yml) covers the common `opencode run` case.\n\n## Token Policy\n\nRefresh tokens are **mandatory** for the flows that issue them.\n\n- `authorization_code` / `device_code` exchanges that don't return `refresh_token` are rejected.\n- Cached tokens missing `refreshToken` are evicted on load (unless they're from `client_credentials` / `jwt_bearer` / `token_exchange`, which don't issue one).\n- Refresh responses that omit a new `refresh_token` re-use the existing one.\n\nThe intent: a user-flow session is either fully renewable or it doesn't get cached. Machine flows re-acquire on every expiry; refresh tokens have no role there.\n\n## Workspace Layout\n\nThis is a [pnpm](https://pnpm.io) monorepo.\n\n| Package | Purpose |\n| --- | --- |\n| [`packages/opencode-oauth2`](packages/opencode-oauth2) | The runtime plugin — published as `@vymalo/opencode-oauth2` |\n| [`packages/plugin-bundle`](packages/plugin-bundle) | Rolldown-based bundling for distribution |\n| [`plans/prd.md`](plans/prd.md) | Product requirements and phased roadmap |\n\n## Development\n\n```sh\npnpm install\npnpm build\npnpm typecheck\npnpm test\n```\n\nPlugin-only iteration:\n\n```sh\npnpm --filter @vymalo/opencode-oauth2 test\npnpm --filter @vymalo/opencode-oauth2 build\n```\n\nFor end-to-end usage against a local OpenCode install, see [GETTING_STARTED.md](GETTING_STARTED.md).\n\n## Status\n\nEarly but functional. The Phase 1 scaffold and Phase 2 runtime core are in; bundling (Phase 3) has landed. Public API may still shift before `1.0`.\n\nRoadmap and phase breakdown live in [plans/prd.md](plans/prd.md).\n\n## Contributing\n\nIssues and PRs are welcome. Please open an issue first for substantial changes so we can align on scope before code review.\n\n## License\n\n[MIT](LICENSE) © vymalo contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvymalo%2Fopencode-oauth2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvymalo%2Fopencode-oauth2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvymalo%2Fopencode-oauth2/lists"}