Skip to content

Add oc-chatgpt-multi-auth authentication support#120

Merged
kargnas merged 3 commits intomainfrom
codex-oc-chatgpt-multi-auth-recognition
Apr 3, 2026
Merged

Add oc-chatgpt-multi-auth authentication support#120
kargnas merged 3 commits intomainfrom
codex-oc-chatgpt-multi-auth-recognition

Conversation

@kargnas
Copy link
Copy Markdown
Member

@kargnas kargnas commented Apr 3, 2026

Summary

  • add detection for ndycode/oc-chatgpt-multi-auth account files under ~/.opencode and merge them with the existing ChatGPT auth sources
  • parse plugin-managed OpenCode auth.json OpenAI fields such as idToken, accountIdOverride, and organizationIdOverride, then resolve stable ChatGPT account IDs from JWT claims
  • keep ChatGPT usage on the direct endpoint when oc-chatgpt-multi-auth config points OpenCode at a localhost baseURL, and document the new auth discovery paths

Testing

  • xcodebuild test -project "CopilotMonitor/CopilotMonitor.xcodeproj" -scheme "CopilotMonitor" -configuration Debug -destination 'platform=macOS' -only-testing:CopilotMonitorTests/TokenManagerTests
  • /Users/kargnas/Library/Developer/Xcode/DerivedData/CopilotMonitor-bkagskdhlwoqyngsvfpyffhstcmu/Build/Products/Debug/opencodebar-cli provider codex

@kargnas kargnas marked this pull request as ready for review April 3, 2026 16:24
@op-gg-ai-devops
Copy link
Copy Markdown
Contributor

op-gg-ai-devops bot commented Apr 3, 2026

❌ AI Code Review Cancelled

Newer commit detected or workflow was manually cancelled.


📋 View Logs | 🤖 Model: openrouter/qwen/qwen3.6-plus:free

@kargnas kargnas force-pushed the codex-oc-chatgpt-multi-auth-recognition branch from 4f428e1 to 77845ff Compare April 3, 2026 16:30
@op-gg-ai-devops
Copy link
Copy Markdown
Contributor

op-gg-ai-devops bot commented Apr 3, 2026

✅ AI Code Review Completed

review posting completed.

🤖 OP.GG AI DevOps 코드 리뷰 현황

상태 작업 결과
Read PR context, determine language, check PR size PR 컨텍스트 읽고 언어 설정이랑 사이즈 확인 완료
Pre-processing: resolved issues, library research, repo context 관련 이슈랑 라이브러리, 레포 컨텍스트 다 파악했음
Read full diff and analyze all changed files 코드 변경점 싹 다 읽고 분석 마침
Run smoke tests (build/typecheck) 빌드랑 타입 체크 스모크 테스트 돌려봤음
Check CI status and existing reviews CI 상태랑 기존에 달린 리뷰들 체크 완료
Write review_payload.json 리뷰 페이로드(review_payload.json) 작성 끝남
Post review review posting completed.

Reviewed with openrouter/qwen/qwen3.6-plus:free


📋 View Full Logs

Copy link
Copy Markdown
Contributor

@op-gg-ai-devops op-gg-ai-devops bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oc-chatgpt-multi-auth Support — Solid Addition

Clean integration of the ndycode/oc-chatgpt-multi-auth plugin ecosystem into the existing multi-source account discovery pipeline. The approach is well-aligned with the codebase's established patterns.

What's Good

  • JWT claim canonicalization — Extracting stable chatgpt_account_id from access token claims instead of relying on potentially org-scoped accountId is the right call. This matches the codebase's existing Subscription Key Stability (Email-First Rule) pattern nicely.
  • resolvedOpenAIAuthMetadata centralization — Instead of scattering JWT decode + field resolution logic, this helper struct consolidates it. All call sites (getOpenAIAccounts, getOpenAIAccountId, diagnostics, debug dump) go through the same path. Clean.
  • Caching follows existing patternscachedOpenCodeMultiAuthAccounts / timestamp pair mirrors the existing cache strategy. No surprises.
  • Test coverage — 3 new test cases covering endpoint config override, field decoding, and account ID canonicalization from JWT. The makeTestJWT helper is reusable for future tests too.
  • Documentation is thorough — README, API reference, and auth file format docs all updated with the new paths and behavior. The explanation of why the localhost proxy is ignored for usage requests is particularly helpful.

Minor Observations

  • The readOpenAIMultiAuthFiles(at:) is func (internal) rather than private func, which is intentional for test access — makes sense.
  • openCodeMultiAuthPaths() uses contentsOfDirectory which returns both files and directories under ~/.opencode/projects/, but readJSONDictionary gracefully handles non-existent paths, so no issue.
  • The default.profraw removal is a nice cleanup.

All CI checks (Lint, Test, CI, Build and Release) passed. No blockers found.


Reviewed with openrouter/qwen/qwen3.6-plus:free

}

private func extractOpenAIMultiAuthPayload(from dict: [String: Any]) -> OpenAIMultiAuthPayload? {
let accessKeys: Set<String> = ["accesstoken", "access", "oauthtoken", "token"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Edge%20Case Broad 'id' key match in recursive search: potential false positive
The accountKeys set includes "id" as a normalized match. Since findStringValue does recursive dictionary traversal, this could accidentally match an unrelated id field nested somewhere deeper in an unexpected JSON structure. Given that findDirectStringValue is checked first and the actual account file schema is fairly flat, this is unlikely to be a problem in practice — but worth noting as a potential false-positive source if the plugin's JSON format ever nests objects with their own id fields.

Consider removing "id" from the set or limiting the recursive search depth to 1 level for account key lookup.

lines.append(" oc-chatgpt-multi-auth accounts (\(shortPath(defaultOpenCodeAccounts.path))): NOT FOUND")
} else {
for path in existingOpenCodeMultiAuthPaths {
let accountCount = readOpenAIMultiAuthFiles(at: [path]).count
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Perf Redundant file re-parse in diagnostics loop
This calls readOpenAIMultiAuthFiles(at: [path]) per path inside the diagnostics loop, re-parsing each file individually. The cached result from readOpenAIMultiAuthFiles() (no-args, line ~4670) was already loaded above. You could filter the cached accounts by authSource to get per-path counts instead of re-reading and re-parsing each file:

let accountCount = openCodeMultiAuthAccounts.filter { $0.authSource == path.path }.count

Not a correctness issue, but avoids redundant file I/O in the diagnostics path.

@kargnas kargnas merged commit 568aa31 into main Apr 3, 2026
13 checks passed
@kargnas kargnas deleted the codex-oc-chatgpt-multi-auth-recognition branch April 3, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant