[PR #10528] feat(auth): merge auth methods from multiple plugins for same provider #13474

Open
opened 2026-02-16 18:18:19 -05:00 by yindo · 0 comments
Owner

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

State: open
Merged: No


Summary

When multiple plugins register for the same provider (e.g., openai), all their auth methods are now merged into a single list. This allows external plugins to add auth methods alongside built-in options.

Problem

Currently, auth.ts:310 uses .find() which returns the first matching plugin:

const plugin = await Plugin.list().then((x) => x.find((x) => x.auth?.provider === provider))

Since internal plugins load before external plugins, external plugins can never add auth methods to providers that have internal plugins (like openai).

Solution

Added getMergedPluginAuth() function that:

  1. Uses .filter() to collect ALL plugins that register for a provider
  2. Uses .flatMap() to merge all their auth methods
  3. Uses the first plugin's loader (internal plugins still take precedence)

Use Case

Multi-account authentication plugins can add their auth methods alongside built-in options:

Before:

  • ChatGPT Pro/Plus
  • Manually enter API Key

After:

  • ChatGPT Pro/Plus (built-in)
  • ChatGPT Pro/Plus Multi-Account (external plugin)
  • Manually enter API Key (built-in)

Backward Compatibility

  • Single-plugin providers: No change in behavior
  • Multi-plugin providers: Methods are merged, first plugin's loader used
  • No breaking changes to existing plugins or configurations

Testing

  1. Install an external plugin that registers for openai provider
  2. Run opencode auth login → select "OpenAI"
  3. Verify both internal and external auth methods appear in the list
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10528 **State:** open **Merged:** No --- ## Summary When multiple plugins register for the same provider (e.g., `openai`), all their auth methods are now merged into a single list. This allows external plugins to add auth methods alongside built-in options. ## Problem Currently, `auth.ts:310` uses `.find()` which returns the first matching plugin: ```typescript const plugin = await Plugin.list().then((x) => x.find((x) => x.auth?.provider === provider)) ``` Since internal plugins load before external plugins, external plugins can never add auth methods to providers that have internal plugins (like `openai`). ## Solution Added `getMergedPluginAuth()` function that: 1. Uses `.filter()` to collect ALL plugins that register for a provider 2. Uses `.flatMap()` to merge all their auth methods 3. Uses the first plugin's loader (internal plugins still take precedence) ## Use Case Multi-account authentication plugins can add their auth methods alongside built-in options: **Before:** - ChatGPT Pro/Plus - Manually enter API Key **After:** - ChatGPT Pro/Plus (built-in) - ChatGPT Pro/Plus Multi-Account (external plugin) - Manually enter API Key (built-in) ## Backward Compatibility - Single-plugin providers: No change in behavior - Multi-plugin providers: Methods are merged, first plugin's loader used - No breaking changes to existing plugins or configurations ## Testing 1. Install an external plugin that registers for `openai` provider 2. Run `opencode auth login` → select "OpenAI" 3. Verify both internal and external auth methods appear in the list
yindo added the pull-request label 2026-02-16 18:18:19 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13474