Skip to content

fix(auth/external): tolerate OpenCode Go auth.json schema variants (#171)#248

Merged
quangdang46 merged 1 commit into
masterfrom
fix/opencode-go-auth-schema-tolerance
May 23, 2026
Merged

fix(auth/external): tolerate OpenCode Go auth.json schema variants (#171)#248
quangdang46 merged 1 commit into
masterfrom
fix/opencode-go-auth-schema-tolerance

Conversation

@quangdang46
Copy link
Copy Markdown
Owner

Symptom

jcode server fails with 'No credentials configured' even though OpenCode Go login succeeded.

Root cause

extract_api_key for ExternalAuthSource::OpenCode only accepted the original schema:

{"type": "api", "key": "..."}

But OpenCode Go and several forks now ship:

Shape Source
{"type": "api", "api_key": "..."} OpenCode Go newer
{"type": "key", "key": "..."} self-hosted forks
{ "key": "..." } (no type) various
{ "token": "..." } OpenCode Go alt naming

Fix

extract_api_key now accepts all four:

  • type optional; if present must be "api" or "key"
  • key field tried in order: keyapi_keyapiKeytoken

OAuth-typed entries still rejected here (they go through the dedicated OAuth path).

Tests

$ cargo test -p jcode --lib auth::external
test result: ok. 10 passed; 0 failed

4 new tests covering each schema variant + an oauth-typed-entry negative test.

Closes #171.

)

Reported symptom: jcode server fails to start with 'No credentials
configured' even though OpenCode Go login succeeded. Root cause: the
parser only accepts the original OpenCode schema:

  {"type": "api", "key": "..."}

OpenCode Go and several forks now ship variants:

  {"type": "api", "api_key": "..."}    OpenCode Go newer
  {"type": "key", "key": "..."}        some self-hosted forks
  {                "key": "..."}        type field absent
  {                "token": "..."}      OpenCode Go alt naming

extract_api_key now accepts all four shapes:
- type field optional; if present must be "api" or "key"
- key field tried in order: "key" → "api_key" → "apiKey" → "token"

OAuth-typed entries (type=="oauth") still rejected here so they go
through the dedicated OAuth path — verified by a new regression test.

4 new tests:
- opencode_api_key_accepts_api_key_field (OpenCode Go newer)
- opencode_api_key_accepts_token_field (forks)
- opencode_api_key_accepts_missing_type_field (loose)
- opencode_api_key_rejects_oauth_typed_entry (negative)

Closes #171.
@quangdang46 quangdang46 merged commit 65e18d9 into master May 23, 2026
@quangdang46 quangdang46 deleted the fix/opencode-go-auth-schema-tolerance branch May 23, 2026 10:11
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.

[Upstream #234] Bug: Server fails to start with "No credentials configured" error despite successful OpenCode Go auth

1 participant