Skip to content

Github Enterprise authorization #3936

Closed

Description

@rdentato

Description

Got an Unexpected Error while trying to login with a Github Enterprise login:

┌  Add credential
│
◇  Select provider
│  GitHub Copilot
│
◇  Select GitHub deployment type
│  GitHub Enterprise
│
◇  Enter your GitHub Enterprise URL or domain
│  https://github.my-company-domain.com
Error: Unexpected error, check log file at /home/remo/.local/share/opencode/log/2025-11-05T113425.log for more details

192 |                 scope: "read:user",
193 |               }),
194 |             });
195 |
196 |             if (!deviceResponse.ok) {
197 |               throw new Error("Failed to initiate device authorization");
                              ^
error: Failed to initiate device authorization
      at authorize (/home/remo/.cache/opencode/node_modules/opencode-copilot-auth/index.mjs:197:25)
      at processTicksAndRejections (native:7:39)

I can login to my company Github via web just fine. The actual name of the company has been hidden for privacy reason.

The last lines of the log file are:

INFO  2025-11-05T11:34:27 +5ms service=plugin path=opencode-copilot-auth@0.0.4 loading plugin
INFO  2025-11-05T11:34:27 +15ms service=plugin path=opencode-anthropic-auth@0.0.2 loading plugin
ERROR 2025-11-05T11:34:44 +17640ms service=default name=Error message=Failed to initiate device authorization stack=Error: Failed to initiate device authorization
    at authorize (/home/remo/.cache/opencode/node_modules/opencode-copilot-auth/index.mjs:197:25)
    at processTicksAndRejections (native:7:39) fatal

OpenCode version

10.0.25

Steps to reproduce

  1. run "opencode auth login"
  2. choose "Github Copilot"
  3. choose "GitHub Enterprise"
  4. enter the doain name "https://github.my-company-domain.com" (actual domain hidden for privacy reasons)

Screenshot and/or share link

No response

Operating System

Windows 11 + WSL2 Ubuntu 24.04

Terminal

Windows Terminal

Activity

  1. github-actions commented on Nov 5, 2025

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Both of these existing issues highlight that OpenCode currently only supports Copilot auth using the standard github.com domain, which appears to be the root cause of your "Failed to initiate device authorization" error when trying to use your GitHub Enterprise domain.

    Feel free to ignore if none of these address your specific case.

  2. rekram1-node commented on Nov 5, 2025

    @rekram1-node
    Contributor

    i would need to have a second glance at rhe code, but for domain name are you including an https prefix? I think it is looking just for the domain name not the url

  3. removed
    webRelates to opencode on web / desktop
    on Nov 5, 2025
  4. rdentato commented on Nov 5, 2025

    @rdentato
    Author

    I tried with:

    I access my company GitHub with: https://github.my-company.com and I checked that the htts:://github.my-company.com/login/device works properly.

    The URL copilot-api.github.my-company.com and api.github.my-company.com do NOT work (not sure if they should, I just checked).
    The URL https://api.my-company.ghe.com/ returns "Couldn't find Business with slug = my-company"

  5. rekram1-node commented on Nov 10, 2025

    @rekram1-node
    Contributor

    Im gonna fix this today Ik the bug

  6. rdentato commented on Nov 12, 2025

    @rdentato
    Author

    Great! In the meantime I noticed that I can login to github.com using my company name: "name-surname_cmpny"
    the "_cmpny" at the end triggers the SSO with my company and I can login exactly as I had used "https://github.cmpny.com/"
    Maybe is a different type of integration than having a "ghe.com" name?

  7. rekram1-node commented on Nov 12, 2025

    @rekram1-node
    Contributor

    yeah i think ur right

  8. jolo-dev commented on Jan 3, 2026

    @jolo-dev

    Any progress on this? I am facing the same issue!

  9. maaaark commented on Jan 15, 2026

    @maaaark

    I am having the same issue login to ghe.com..
    Also there is no way to login the ghe.com in the GUI right? Only by TUI?

    Here is the auth with logs:

    ` opencode --print-logs auth login
    INFO 2026-01-15T18:29:01 +202ms service=default version=1.1.22 args=["--print-logs","auth","login"] opencode
    INFO 2026-01-15T18:29:01 +0ms service=default directory=D:\web\trails creating instance
    INFO 2026-01-15T18:29:01 +0ms service=project directory=D:\web\trails fromDirectory

    ┌ Add credential
    INFO 2026-01-15T18:29:01 +31ms service=models.dev file={} refreshing
    INFO 2026-01-15T18:29:02 +163ms service=config path=C:\Users\markt.config\opencode\config.json loading
    INFO 2026-01-15T18:29:02 +0ms service=config path=C:\Users\markt.config\opencode\opencode.json loading
    INFO 2026-01-15T18:29:02 +0ms service=config path=C:\Users\markt.config\opencode\opencode.jsonc loading
    INFO 2026-01-15T18:29:02 +3ms service=bun cmd=["C:\Users\markt\AppData\Roaming\npm\node_modules\opencode-ai\node_modules\opencode-windows-x64\bin\opencode.exe","add","@opencode-ai/plugin@1.1.22","--exact"] cwd=C:\Users\markt.config\opencode running
    INFO 2026-01-15T18:29:02 +10ms service=models.dev file={} refreshing
    │
    ◆ Select provider

    │ Search: _
    │ ● OpenCode Zen (recommended)
    │ ○ Anthropic
    │ ○ GitHub Copilot
    │ ○ OpenAI
    │ ○ Google
    │ ○ OpenRouter
    │ ○ Vercel AI Gateway
    │ ...
    ◇ Select provider
    │ GitHub Copilot
    INFO 2026-01-15T18:29:31 +29545ms service=plugin name=CodexAuthPlugin loading internal plugin
    INFO 2026-01-15T18:29:31 +0ms service=plugin name=CopilotAuthPlugin loading internal plugin
    INFO 2026-01-15T18:29:31 +0ms service=plugin path=opencode-anthropic-auth@0.0.9 loading plugin
    INFO 2026-01-15T18:29:31 +21ms service=plugin path=@gitlab/opencode-gitlab-auth@1.3.0 loading plugin
    │
    ◇ Select GitHub deployment type
    │ GitHub Enterprise
    │
    ◇ Enter your GitHub Enterprise URL or domain
    │ https://XXXXXXXXXXX.ghe.com
    ERROR 2026-01-15T18:29:54 +22115ms service=default name=Error message=Failed to initiate device authorization stack=Error: Failed to initiate device authorization
    at authorize (src/plugin/copilot.ts:172:25)
    at processTicksAndRejections (native:7:39) fatal
    Error: Unexpected error, check log file at for more details

    Failed to initiate device authorization`

    Any help or hint would be nice :)

  10. rekram1-node commented on Jan 15, 2026

    @rekram1-node
    Contributor

    working w/ copilot team to get this figured out

  11. 36 remaining items

  12. davidraehles commented on Feb 18, 2026

    @davidraehles

    @WilliamWelsh ran into the same issue afterwards. But Opus 4.6 found a fix:

    Complete Working Solution

    The fix requires two pieces working together:

    Piece 1: JWT Refresh Cron Job

    Since OpenCode doesn't do token exchange and its OAuth app is rejected by the token exchange endpoint, a cron job exchanges the token externally:

    1. Authenticates using VS Code's OAuth App (client_id 01ab8ac9400c4e429b23)
    2. Exchanges the gho_ token for a Copilot JWT
    3. Injects the JWT into OpenCode's auth.json
    4. Runs every 25 minutes via cron (JWT expires after 30)

    Piece 2: Editor-Version Header via opencode.json

    The Copilot API requires Editor-Version for JWT auth. Add per-model headers:

    {
      "provider": {
        "github-copilot-enterprise": {
          "models": {
            "claude-opus-4.6": {
              "headers": {
                "Editor-Version": "vscode/1.100.0",
                "Copilot-Integration-Id": "vscode-chat"
              }
            },
            "claude-sonnet-4": {
              "headers": {
                "Editor-Version": "vscode/1.100.0",
                "Copilot-Integration-Id": "vscode-chat"
              }
            },
            "gpt-5": {
              "headers": {
                "Editor-Version": "vscode/1.100.0",
                "Copilot-Integration-Id": "vscode-chat"
              }
            },
            "gpt-5-mini": {
              "headers": {
                "Editor-Version": "vscode/1.100.0",
                "Copilot-Integration-Id": "vscode-chat"
              }
            },
            "gemini-2.5-pro": {
              "headers": {
                "Editor-Version": "vscode/1.100.0",
                "Copilot-Integration-Id": "vscode-chat"
              }
            }
          }
        }
      }
    }

    Verification

    # Test with opencode run (non-interactive)
    opencode run --model github-copilot-enterprise/claude-opus-4.6 "Say SUCCESS"
    # Expected: "> build · claude-opus-4.6\nSUCCESS"
  13. WilliamWelsh commented on Feb 18, 2026

    @WilliamWelsh

    @davidraehles that worked!

    {
      "$schema": "https://opencode.ai/config.json",
      "provider": {
        "github-copilot-enterprise": {
          "models": {
            "gpt-5.2-codex": {
              "headers": {
                "Editor-Version": "vscode/1.100.0",
                "Copilot-Integration-Id": "vscode-chat"
              }
            },
            "gpt-5.3-codex": {
              "headers": {
                "Editor-Version": "vscode/1.100.0",
                "Copilot-Integration-Id": "vscode-chat"
              }
            }
          }
        }
      }
    }

    Hopefully this entire issue is resolved eventually so I don't have to run this daemon script and manually add models like this, but thanks!

  14. rekram1-node commented on Feb 19, 2026

    @rekram1-node
    Contributor

    The reason it worked is because of this:

    Authenticates using VS Code's OAuth App (client_id 01ab8ac9400c4e429b23)

    We are not allowed to use that id.

    Still waiting for full enterprise rollout but I will keep yall posted. Nothing left on our end we wait for github ppl.

  15. WilliamWelsh commented on Mar 16, 2026

    @WilliamWelsh

    1 month later ;-;
    is there anyone at GitHub we can ping? seems kind of crazy considering how popular OpenCode is

  16. rekram1-node commented on Mar 16, 2026

    @rekram1-node
    Contributor

    @WilliamWelsh can u test this branch? Ill merge it later:
    #17847

    u should be able to test w/ bunx opencode-ai@beta

    Or using npm or pnpm

  17. rekram1-node commented on Mar 16, 2026

    @rekram1-node
    Contributor

    There may be bugs I just don't have a way to test, and to login w/ copilot enterprise use opencode auth login instead of /connect

  18. WilliamWelsh commented on Mar 16, 2026

    @WilliamWelsh

    @rekram1-node Appears to be working! I even removed my opencode.json which had the vscode-chat stuff

    Image Image
  19. rekram1-node commented on Mar 16, 2026

    @rekram1-node
    Contributor

    Sweet! Okay ill add /connect support for it too then (so that it prompts u for enterprise)

    Thanks for helping me out

  20. Raviguntakala commented on Mar 17, 2026

    @Raviguntakala
    Contributor

    Sweet! Okay ill add /connect support for it too then (so that it prompts u for enterprise)

    Thanks for helping me out

    @rekram1-node I already created a PR #6974 for this one long back. If you want to use this one, I can resolve conflicts

  21. STSMHQ commented on Mar 17, 2026

    @STSMHQ

    Thanks a lot, guys! This is great.

  22. rekram1-node commented on Mar 17, 2026

    @rekram1-node
    Contributor

    Ill take a look at the pr, the conditional thingy is a little weird to do over http so ill check ur implementation

  23. jolo-dev commented on Mar 18, 2026

    @jolo-dev

    It seems to work. I can access all models from our enterprise subscription following their docs
    https://opencode.ai/docs/providers/#github-copilot

  24. rekram1-node commented on Mar 18, 2026

    @rekram1-node
    Contributor

    next release should have /connect support working properly.

    that will close out this issue

  25. alexandre-thauvin commented on May 5, 2026

    @alexandre-thauvin

    Hello @rekram1-node I have the an issue related to authorization when trying to connect Github Copilot Enterprise after entering my company github domain in the tui:

    Image

    Setup:
    Device: Mac M4 OS - Tahoe 26.4.1
    Terminal: Kitty
    OpenCode version: 1.14.31
    Default browser: Brave (Tried Safari as well)
    Logs:

    INFO  2026-05-05T07:33:59 +143ms service=default version=1.14.31 args=["auth","login"] process_role=main run_id=6e424fb1-1629-4934-b48e-effebde6e7d2 opencode
    INFO  2026-05-05T07:33:59 +0ms service=default directory=/Users/athauvin creating instance
    INFO  2026-05-05T07:33:59 +2ms service=project directory=/Users/athauvin fromDirectory
    INFO  2026-05-05T07:33:59 +2ms service=db path=/Users/athauvin/.local/share/opencode/opencode.db opening database
    INFO  2026-05-05T07:33:59 +4ms service=db count=14 mode=bundled applying migrations
    ERROR 2026-05-05T07:33:59 +115ms service=models.dev error=unable to get local issuer certificate Failed to fetch models.dev
     ROR 2026-05-05T07:33:59 +87ms service=models.dev error=unable to get local issuer rtificate Failed to fetch models.dev
    INFO  2026-05-05T07:33:59 +8ms service=file init
    INFO  2026-05-05T07:34:00 +24ms service=config path=/Users/athauvin/.config/opencode/config.json loading
    INFO  2026-05-05T07:34:00 +0ms service=config path=/Users/athauvin/.config/opencode/opencode.json loading
    INFO  2026-05-05T07:34:00 +0ms service=config path=/Users/athauvin/.config/opencode/opencode.jsonc loading
    INFO  2026-05-05T07:34:00 +16ms service=plugin name=cH loading internal plugin
    INFO  2026-05-05T07:34:00 +0ms service=plugin name=sH loading internal plugin
    INFO  2026-05-05T07:34:00 +0ms service=plugin name=zj loading internal plugin
    INFO  2026-05-05T07:34:00 +0ms service=plugin name=FZ loading internal plugin
    INFO  2026-05-05T07:34:00 +0ms service=plugin name=Fj loading internal plugin
    INFO  2026-05-05T07:34:00 +0ms service=plugin name=wj loading internal plugin
    INFO  2026-05-05T07:34:00 +0ms service=plugin name=Uj loading internal plugin
    INFO  2026-05-05T07:34:00 +1ms service=bus type=* subscribing
    ERROR 2026-05-05T07:34:05 +5651ms service=default name=Error message=Failed to initiate device authorization stack=Error: Failed to initiate device authorization
        at authorize (/$bunfs/root/chunk-7kndgn7w.js:521:12699)
        at processTicksAndRejections (native:7:39) fatal
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions