[PR #11058] fix: allow user plugins to override built-in auth plugins #13644

Closed
opened 2026-02-16 18:18:29 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11058

State: closed
Merged: Yes


Fixes #11475

Change .find() to .findLast() in CLI auth flow so user plugins take precedence over internal plugins (e.g., github-copilot). This aligns CLI behavior with ProviderAuth.methods() which already uses last-wins semantics via fromEntries().

What does this PR do?

Fixes a bug where user/external plugins cannot override built-in auth plugins. The root cause is that Plugin.list() returns internal plugins first, then user plugins. The CLI auth command used .find() (first match wins), meaning the built-in plugin always took precedence. Meanwhile, ProviderAuth.methods() (used by TUI) already used fromEntries() which is last-wins.

This PR changes two .find() calls to .findLast() in packages/opencode/src/cli/cmd/auth.ts so user plugins can fully override built-in auth behavior (e.g., a company plugin replacing the default GitHub Copilot OAuth flow with a custom enterprise auth).

How did you verify your code works?

Added packages/opencode/test/plugin/auth-override.test.ts which:

  1. Creates a temp directory with a user plugin that registers auth.provider: "github-copilot" with a custom method
  2. Calls ProviderAuth.methods() and asserts the user plugin's method takes precedence over the built-in
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11058 **State:** closed **Merged:** Yes --- Fixes #11475 Change `.find()` to `.findLast()` in CLI auth flow so user plugins take precedence over internal plugins (e.g., github-copilot). This aligns CLI behavior with `ProviderAuth.methods()` which already uses last-wins semantics via `fromEntries()`. ### What does this PR do? Fixes a bug where user/external plugins cannot override built-in auth plugins. The root cause is that `Plugin.list()` returns internal plugins first, then user plugins. The CLI auth command used `.find()` (first match wins), meaning the built-in plugin always took precedence. Meanwhile, `ProviderAuth.methods()` (used by TUI) already used `fromEntries()` which is last-wins. This PR changes two `.find()` calls to `.findLast()` in `packages/opencode/src/cli/cmd/auth.ts` so user plugins can fully override built-in auth behavior (e.g., a company plugin replacing the default GitHub Copilot OAuth flow with a custom enterprise auth). ### How did you verify your code works? Added `packages/opencode/test/plugin/auth-override.test.ts` which: 1. Creates a temp directory with a user plugin that registers `auth.provider: "github-copilot"` with a custom method 2. Calls `ProviderAuth.methods()` and asserts the user plugin's method takes precedence over the built-in
yindo added the pull-request label 2026-02-16 18:18:29 -05:00
yindo closed this issue 2026-02-16 18:18:29 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13644