summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJoscha Götzer <[email protected]>2026-02-01 17:50:41 +0100
committerGitHub <[email protected]>2026-02-01 10:50:41 -0600
commit3577d829c2b0002e3697932b71a22dd9fbabc28a (patch)
tree803283da5b12c3808e02239e85f34eaf40c0b47c
parent29d02d643b8f1dcea8e86fe3d6f0530876340120 (diff)
downloadopencode-3577d829c2b0002e3697932b71a22dd9fbabc28a.tar.gz
opencode-3577d829c2b0002e3697932b71a22dd9fbabc28a.zip
fix: allow user plugins to override built-in auth plugins (#11058)
Co-authored-by: JosXa <[email protected]>
-rw-r--r--packages/opencode/src/cli/cmd/auth.ts4
-rw-r--r--packages/opencode/test/plugin/auth-override.test.ts44
2 files changed, 46 insertions, 2 deletions
diff --git a/packages/opencode/src/cli/cmd/auth.ts b/packages/opencode/src/cli/cmd/auth.ts
index bbaecfd8c..34e2269d0 100644
--- a/packages/opencode/src/cli/cmd/auth.ts
+++ b/packages/opencode/src/cli/cmd/auth.ts
@@ -307,7 +307,7 @@ export const AuthLoginCommand = cmd({
if (prompts.isCancel(provider)) throw new UI.CancelledError()
- const plugin = await Plugin.list().then((x) => x.find((x) => x.auth?.provider === provider))
+ const plugin = await Plugin.list().then((x) => x.findLast((x) => x.auth?.provider === provider))
if (plugin && plugin.auth) {
const handled = await handlePluginAuth({ auth: plugin.auth }, provider)
if (handled) return
@@ -323,7 +323,7 @@ export const AuthLoginCommand = cmd({
if (prompts.isCancel(provider)) throw new UI.CancelledError()
// Check if a plugin provides auth for this custom provider
- const customPlugin = await Plugin.list().then((x) => x.find((x) => x.auth?.provider === provider))
+ const customPlugin = await Plugin.list().then((x) => x.findLast((x) => x.auth?.provider === provider))
if (customPlugin && customPlugin.auth) {
const handled = await handlePluginAuth({ auth: customPlugin.auth }, provider)
if (handled) return
diff --git a/packages/opencode/test/plugin/auth-override.test.ts b/packages/opencode/test/plugin/auth-override.test.ts
new file mode 100644
index 000000000..d8f8ea455
--- /dev/null
+++ b/packages/opencode/test/plugin/auth-override.test.ts
@@ -0,0 +1,44 @@
+import { describe, expect, test } from "bun:test"
+import path from "path"
+import fs from "fs/promises"
+import { tmpdir } from "../fixture/fixture"
+import { Instance } from "../../src/project/instance"
+import { ProviderAuth } from "../../src/provider/auth"
+
+describe("plugin.auth-override", () => {
+ test("user plugin overrides built-in github-copilot auth", async () => {
+ await using tmp = await tmpdir({
+ init: async (dir) => {
+ const pluginDir = path.join(dir, ".opencode", "plugin")
+ await fs.mkdir(pluginDir, { recursive: true })
+
+ await Bun.write(
+ path.join(pluginDir, "custom-copilot-auth.ts"),
+ [
+ "export default async () => ({",
+ " auth: {",
+ ' provider: "github-copilot",',
+ " methods: [",
+ ' { type: "api", label: "Test Override Auth" },',
+ " ],",
+ " loader: async () => ({ access: 'test-token' }),",
+ " },",
+ "})",
+ "",
+ ].join("\n"),
+ )
+ },
+ })
+
+ await Instance.provide({
+ directory: tmp.path,
+ fn: async () => {
+ const methods = await ProviderAuth.methods()
+ const copilot = methods["github-copilot"]
+ expect(copilot).toBeDefined()
+ expect(copilot.length).toBe(1)
+ expect(copilot[0].label).toBe("Test Override Auth")
+ },
+ })
+ }, 30000) // Increased timeout for plugin installation
+})