feat(accounts): export OpenCode auth json#532
Conversation
Allow users to move a selected account into stock OpenCode without relying on custom multi-account auth fields.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5d915f4f4b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| access_token = self._encryptor.decrypt(account.access_token_encrypted) | ||
| refresh_token = self._encryptor.decrypt(account.refresh_token_encrypted) | ||
| expires = token_expiry_epoch_ms(access_token) or 0 | ||
| opencode_account_id = account.chatgpt_account_id or account.id |
There was a problem hiding this comment.
Preserve null OpenCode accountId when ChatGPT ID is missing
Falling back to account.id here can generate an authJson.openai.accountId value that is not a real ChatGPT account ID (e.g. deduplicated IDs like acc_xxx_<hash> or local fallback IDs). For accounts where chatgpt_account_id is absent, this exports a misleading accountId instead of leaving it unset, and OpenCode will then send that invalid value as ChatGPT-Account-Id, which can cause downstream auth/account selection failures for those exported credentials.
Useful? React with 👍 / 👎.
Summary
auth.jsonpayloads.Changes
POST /api/accounts/{account_id}/export/opencode-authendpoint.auth.json.expiresfrom the access token JWTexpclaim in epoch milliseconds.account_auth_exportedwithout logging token material.Export OpenCode authaction to account details.auth.jsoncomplete while truncating long tokens visually.add-opencode-auth-exportproposal, design, specs, tasks, and verification report.Test Plan
.venv\Scripts\python -m pytest tests/integration/test_account_opencode_auth_export.py tests/unit/test_auth.py -q -ra6 passed, 1 skippedbun run test src/features/accounts/schemas.test.ts src/features/accounts/components/opencode-auth-export-dialog.test.tsx2 files passed, 8 tests passedauth.jsoncopy/download still works.openspec validate --specsopenspecCLI is not installed/available on PATH.Notes
{ "openai": { "type": "oauth", "refresh": "...", "access": "...", "expires": 1234567890000, "accountId": "..." } }