Skip to content

feat(provider): add GitHub Enterprise support for Copilot - #2522

Merged
rekram1-node merged 16 commits into
anomalyco:devfrom
OlaHulleberg:dev
Nov 4, 2025
Merged

rekram1-node merged 16 commits into
anomalyco:devfrom
OlaHulleberg:dev

Conversation

@OlaHulleberg

@OlaHulleberg OlaHulleberg commented Sep 9, 2025 •

Copy link
Copy Markdown
Contributor

Solves

Summary

Add universal prompts support for OAuth and API authentication methods, enabling plugins to provide better configuration UX. This enables the GitHub Copilot plugin to support both GitHub.com and GitHub Enterprise deployments with a unified auth flow.

Changes

This PR extends the plugin authentication system to support more advanced auth flows:

  • Universal prompts: OAuth and API auth methods can now include preliminary prompts for configuration
  • Select and text prompts: Support both select dropdowns and text input with validation
  • Conditional prompts: Prompts can be conditionally shown based on previous inputs
  • Provider override: Auth methods can specify which provider ID to save credentials under
  • Custom fetch preservation: Preserve custom fetch functions when wrapping with timeout logic
  • Enterprise provider registration: Automatically register github-copilot-enterprise provider
  • Enterprise-only auth support: Allow github-copilot plugin to load when user only has enterprise auth (doesn't affect normal GitHub.com users)

Implementation Details

Plugin Interface (packages/plugin/src/index.ts):

  • Added prompts field to OAuth and API auth method types
  • Support for select prompts (with options and hints) and text prompts (with validation)
  • condition function allows prompts to be shown based on previous input values
  • Added optional provider field to auth success results for override

Auth Command (packages/opencode/src/cli/cmd/auth.ts):

  • Process prompts before calling authorize() for all auth types
  • Pass collected inputs to authorize() function
  • Preserve extra OAuth fields (like enterpriseUrl) when saving auth results

Provider (packages/opencode/src/provider/provider.ts):

  • Register github-copilot-enterprise provider that inherits from github-copilot
  • Load auth for both github-copilot and github-copilot-enterprise when plugin exists
  • Check for enterprise auth as fallback if normal auth doesn't exist (allows enterprise-only usage)
  • Preserve custom fetch functions when wrapping with timeout logic (fixes #TBD)

Related

@OlaHulleberg OlaHulleberg changed the title feat: add GitHub Enterprise Server support for Copilot authentication feat(provider): add GitHub Enterprise Server support for Copilot authentication Sep 9, 2025
@OlaHulleberg OlaHulleberg changed the title feat(provider): add GitHub Enterprise Server support for Copilot authentication feat(provider): add GitHub Enterprise support for Copilot Sep 9, 2025
@OlaHulleberg

Copy link
Copy Markdown
Contributor Author

I will keep rebasing on top so that this branch can be checked out if you want to use Copilot Enterprise with the latest features

@OlaHulleberg
OlaHulleberg force-pushed the dev branch 2 times, most recently from 1dcadfb to 5b94852 Compare September 12, 2025 14:05
@jayair jayair assigned jayair and thdxr and unassigned jayair Sep 12, 2025
@OlaHulleberg
OlaHulleberg force-pushed the dev branch 2 times, most recently from 2988fcc to 8551924 Compare September 14, 2025 17:13
@OlaHulleberg

Copy link
Copy Markdown
Contributor Author

let me know if there's anything you want changed @thdxr
also feel free to commit to this!

@pale3

pale3 commented Oct 7, 2025

Copy link
Copy Markdown

will this get any attention?

OlaHulleberg and others added 5 commits October 8, 2025 09:50
- Extract URL normalization utilities to reduce code duplication
- Simplify API domain construction logic
- Improve enterprise URL handling consistency between CLI and config
- Allow flexible URL input in auth process with better validation
- Simplify provider logic to only use auth-stored enterpriseUrl
- Update CLI labels for clearer enterprise deployment options
- Remove confusing 'Server' terminology, use 'Enterprise' with descriptive hint
@prskr

prskr commented Oct 29, 2025

Copy link
Copy Markdown

Is there anything anyone could help with here? This is the only blocker why I can't really promote this in my company because we only have GHE and double licensing just because people cannot login to GHE is not really an option 😅 would be really great if this could be tackled in some way any time soon

@rekram1-node

Copy link
Copy Markdown
Member

Checking this out

@rekram1-node

Copy link
Copy Markdown
Member

@OlaHulleberg i would love to merge this, important note: auth/github-copilot.ts wasnt being used and has been deleted now the logic lives here: https://github.com/sst/opencode-copilot-auth

@OlaHulleberg

OlaHulleberg commented Oct 31, 2025 •

Copy link
Copy Markdown
Contributor Author

@OlaHulleberg i would love to merge this, important note: auth/github-copilot.ts wasnt being used and has been deleted now the logic lives here: https://github.com/sst/opencode-copilot-auth

I see!
Currently gone for the weekend, so if you want - just implement this the proper way (in that plugin + here), no need to attribute :)

@rdentato

rdentato commented Nov 1, 2025

Copy link
Copy Markdown

I hope to see this PR merged. It's essential to adopt Opencode in large companies.

@rekram1-node

Copy link
Copy Markdown
Member

Yes definitely this weekend I will handle conflicts, and get this integrated

@OlaHulleberg

Copy link
Copy Markdown
Contributor Author

I've given you write access to the dev branch on my fork, if you want to continue on from here @rekram1-node
either way, thank you for picking this up! I support any action you deem necessary to get this through!

- Inline OAuth device flow logic in handleGithubCopilotAuth()
- Remove auth/github-copilot module (moved to external plugin)
- Update provider loader to work with plugin
- Store enterpriseUrl in auth data for plugin consumption
- Support github.com and enterprise deployments
Resolve conflicts and align with upstream architecture:
- Accept upstream's wellknown auth implementation
- Accept upstream's simplified GitHub install command
- Integrate enterprise support via external plugin approach
- Maintain core's excellent UX for Copilot authentication
@rekram1-node

Copy link
Copy Markdown
Member

going to merge this and stuff, just waiting on dax to give an npm token so I can update https://github.com/sst/opencode-copilot-auth

@OlaHulleberg

Copy link
Copy Markdown
Contributor Author

going to merge this and stuff, just waiting on dax to give an npm token so I can update https://github.com/sst/opencode-copilot-auth

hold on, I'm doing some polishing and fixing some errors I've made in the refactor

@rekram1-node

Copy link
Copy Markdown
Member

yeah ofc i just wanted to state i didnt forget about u i shouldnt have worded it like it is being merged in 5 min haha

@OlaHulleberg

OlaHulleberg commented Nov 3, 2025 •

Copy link
Copy Markdown
Contributor Author

yeah ofc i just wanted to state i didnt forget about u i shouldnt have worded it like it is being merged in 5 min haha

I've been trying to tackle this enterprise URL prompting within the plugin for a bit, and discussed back and forth with AI.
I think the most elegant solution would be to extend the plugin methods type with "configure", or some other way of adding extended "prompting" back from plugins
Please share your input on this @rekram1-node

EDIT:
Otherwise we would have to add github-copilot-enterprise as a provider at models.dev which doesn't sound appealing

Example of how this could look like in core:

if (authorize.method === "configure") {
    const inputs = {}
    for (const prompt of authorize.prompts) {
      const value = await prompts.text({
        message: prompt.message,
        placeholder: prompt.placeholder,
        validate: prompt.validate,
      })
      if (prompts.isCancel(value)) throw new UI.CancelledError()
      inputs[prompt.key] = value
    }
    const result = await authorize.callback(inputs)
    // ... handle result
}

EDIT 2:
Maybe the type custom makes more sense?

if (method.type === "custom") {
    const inputs = {}
    for (const prompt of method.prompts) {
      inputs[prompt.key] = await prompts.text({...})
    }

    const result = await method.authorize(inputs)

    if (result.type === "success") {
      const { type: _, auth_type, ...authData } = result
      await Auth.set(provider, {
        type: auth_type,
        ...authData
      })
    }
}

Extends plugin auth system to support custom authentication flows that can
prompt users for configuration during login. This enables GitHub Copilot
Enterprise support by allowing the plugin to request enterprise URL from users.

Changes:
- Add 'custom' auth type to plugin interface with configurable prompts
- Add handler for custom auth type in core auth command
- Remove hardcoded GitHub Copilot auth logic from core
- Remove github-copilot-enterprise custom loader (now handled by plugin)

The plugin architecture now cleanly separates provider-specific auth logic
from core, making it easier to support providers requiring configuration.
- Add select prompt type to custom auth methods
- Add conditional prompts that only show based on previous inputs
- Allow plugins to specify provider ID for saving auth
- Ensure github-copilot plugin loads when only enterprise auth exists
- Handle undefined values in validate function wrapper
- Add type assertion for dynamic auth data spreading
@OlaHulleberg

Copy link
Copy Markdown
Contributor Author

@rekram1-node opened up this PR in the copilot plugin
https://github.com/sst/opencode-copilot-auth/pull/4

Please go through these changes and highlight decisions you do not agree on!
This provider support was a bit more complex than I initially thought it would be, but I've tried to stick as much as possible to the plugin interface without sacrificing UX.

- Add optional prompts field to OAuth and API auth method types
- OAuth and API types can now ask preliminary questions before auth
- Remove custom auth type entirely (no longer needed)
- Prompts support select and text inputs with conditional display
- Update auth command to handle prompts for all auth types

This enables cleaner plugin architecture where auth types use their
proper patterns (OAuth for OAuth flows) while still supporting
configuration questions upfront.
Preserve custom fetch functions from plugins when wrapping them with
timeout logic. Previously, the timeout wrapper would replace any custom
fetch function, breaking plugins that rely on custom fetch for auth or
other purposes.

Also preserve extra OAuth fields like enterpriseUrl when saving auth
results from plugin callbacks.
@OlaHulleberg

OlaHulleberg commented Nov 4, 2025 •

Copy link
Copy Markdown
Contributor Author

@rekram1-node updated the copilot auth plugin to version 0.0.4 and tested with

bun run dev auth login
bun run dev
image

@rekram1-node

Copy link
Copy Markdown
Member

@OlaHulleberg is that fetch override necessary? Im just surprised why it is needed now and not before

@rekram1-node
rekram1-node merged commit fe94bb8 into anomalyco:dev Nov 4, 2025
@OlaHulleberg

OlaHulleberg commented Nov 4, 2025 •

Copy link
Copy Markdown
Contributor Author

@OlaHulleberg is that fetch override necessary? Im just surprised why it is needed now and not before

I actually asked my own AI agent the same question, here's the response it had:

⏺ Looking at the git history, I can see that users CAN configure a timeout for providers in their opencode.json:

{
"provider": {
"github-copilot": {
"timeout": 60000 // Optional timeout in ms
}
}
}

When a timeout is configured, opencode wraps the fetch function with timeout logic. Here's the issue:

Main repo version (current):
if (options["timeout"] !== undefined && options["timeout"] !== null) {
options["fetch"] = async (input, init) => {
return fetch(input, { ...init, signal: combined }) // Overwrites custom fetch
}
}

Our version (commit 24f1774):
if (options["timeout"] !== undefined && options["timeout"] !== null) {
const customFetch = options["fetch"] // Preserve it
options["fetch"] = async (input, init) => {
const fetchFn = customFetch ?? fetch // Use custom if available
return fetchFn(input, { ...init, signal: combined })
}
}

The problem: If users configure a timeout for GitHub Copilot, the main repo version would overwrite the plugin's custom fetch function, breaking token
refresh.

However, you're right that this feels broader than just the GitHub Copilot Enterprise PR. This is a bug fix for opencode's plugin system in general - ANY
plugin with a custom fetch would break if users configure a timeout.

Should we:

  1. Keep it in this PR (since it's needed for the plugin to work with timeouts)
  2. Submit it as a separate PR (general bug fix unrelated to enterprise support)
  3. Remove it and just document that users shouldn't configure timeouts for GitHub Copilot

What do you think?

I chose to go with option 1, but I can gladly remove it if this is misunderstood

@rekram1-node

Copy link
Copy Markdown
Member

Does it work without that change tho? @OlaHulleberg

@OlaHulleberg

Copy link
Copy Markdown
Contributor Author

the token refreshing has been working for me, but I haven't directly tried configuring timeout for copilot @rekram1-node

@rekram1-node

Copy link
Copy Markdown
Member

okay looking at it again it makes sense, i hate the github view i need to open everything in my ide

@rekram1-node

Copy link
Copy Markdown
Member

Thanks for your work on this btw

Do u have an X/twitter account by chance we like to shout out people

@OlaHulleberg

Copy link
Copy Markdown
Contributor Author

Thanks for your work on this btw

Do u have an X/twitter account by chance we like to shout out people

no need, just glad I can help colleagues try out agentic development at work ;)

github-actions Bot pushed a commit to yuguorui/opencode that referenced this pull request Jan 18, 2026
…2522)

Co-authored-by: Jon-Mikkel Korsvik <[email protected]>
Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: Aiden Cline <[email protected]>
Rwanbt pushed a commit to Rwanbt/unifia that referenced this pull request May 5, 2026
…2522)

Co-authored-by: Jon-Mikkel Korsvik <[email protected]>
Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: Aiden Cline <[email protected]>
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
…2522)

Co-authored-by: Jon-Mikkel Korsvik <[email protected]>
Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: Aiden Cline <[email protected]>
Rwanbt pushed a commit to Rwanbt/unifia that referenced this pull request Jun 14, 2026
…2522)

Co-authored-by: Jon-Mikkel Korsvik <[email protected]>
Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: Aiden Cline <[email protected]>
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.

8 participants