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 👍 / 👎.
# Conflicts: # frontend/src/features/accounts/components/accounts-page.tsx
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 766d2e0b12
ℹ️ 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.
Keep
accountId null when ChatGPT account id is unknown
When chatgpt_account_id is missing, this code falls back to account.id and exports that as authJson.openai.accountId. Internal account IDs can be synthetic (for example email_.../local_... or hashed variants), so the export may inject a non-ChatGPT identifier into OpenCode auth and cause downstream requests to send an invalid account header instead of omitting it. The payload should leave accountId unset/null unless a real ChatGPT account id exists.
Useful? React with 👍 / 👎.
|
Maintainer cleanup: closing this as stale / no longer merge-ready against the current This PR has been open across substantial main-branch churn and is currently carrying at least one stale signal (conflicts/blocked or failing checks, outstanding If the change is still needed, please open a fresh, focused PR rebased on current |
|
Revived on a maintainer-owned branch as #757 because this PR head has maintainerCanModify=false and cannot be updated here. Keeping credit to the original implementation in the replacement PR. |
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": "..." } }