SessionConfig.GitHubToken / GitHubTokenProvider still route to api.github.com instead of the GHEC Data Residency tenant endpoint, even with CopilotClientMode.Empty — same defect class as #4527, unresolved on the SDK session-level path
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 45/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Domaine
- api, authentication, backend-api-design, cli
Piste de recherche
The issue is in the GitHub.Copilot.SDK .NET library, specifically the session authentication code paths for SessionConfig.GitHubToken and GitHubTokenProvider. Start by examining the SDK source for how it resolves the API endpoint for token validation, likely in the Copilot CLI runtime bundled with the SDK. Look for where the tenant host is derived from the token or environment variables, and compare it to the working ambient path (UseLoggedInUser = true). The fix likely involves applying the same endpoint resolution logic used for the ambient path to the session-level credential paths.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Describe the bug
Describe the bug
On a GitHub Enterprise Cloud with Data Residency (GHEC-DR) + EMU tenant (<tenant>.ghe.com), the GitHub.Copilot.SDK (.NET) per-session authentication mechanisms — SessionConfig.GitHubToken (stable field) and SessionConfig.GitHubTokenProvider (experimental field) — fail to route Copilot validation calls to the tenant's own endpoint (api.<tenant>.ghe.com / copilot-api.<tenant>.ghe.com). Instead they fall back to the public api.github.com, which rejects the tenant's gho_ token with 401 Bad credentials.
This is the same defect class as #4527 ("copilot -p fails with 401 on GHEC data residency ... model-catalog fetch hits api.githubcopilot.com instead of the tenant endpoint"), which was fixed for the CLI's non-interactive prompt-mode path. The fix does not appear to cover the SDK's session-level credential-forwarding path used for multi-user/server integrations, which is the officially documented pattern for this exact use case (see SDK README "Advanced Usage" / GitHubTokenProvider docs).
Steps to reproduce the behavior
- Authenticate a web user against
<tenant>.ghe.comvia a standard OAuth Authorization Code flow (separate fromcopilot login), obtaining a validgho_user access token scoped to the tenant. - Create a client explicitly for the documented multi-user/server pattern:
var client = new CopilotClient(new CopilotClientOptions { Mode = CopilotClientMode.Empty, BaseDirectory = "<isolated temp dir>", UseLoggedInUser = false // no GitHubToken set at the client level }); await client.StartAsync(); - Create a session using either documented per-session mechanism:
orvar session = await client.CreateSessionAsync(new SessionConfig { Model = "gpt-5", GitHubToken = userToken, // stable field AvailableTools = new ToolSet().AddBuiltIn(BuiltInTools.Isolated) // required by Mode.Empty });var session = await client.CreateSessionAsync(new SessionConfig { Model = "gpt-5", GitHubTokenProvider = args => Task.FromResult(GitHubTokenProviderResult.FromToken(new GitHubToken { AccessToken = userToken, ExpiresIn = 8 * 60 * 60 })), AvailableTools = new ToolSet().AddBuiltIn(BuiltInTools.Isolated) }); - Send any prompt.
What the user sees
SessionConfig.GitHubToken: CreateSessionAsync throws with:
Communication error with Copilot CLI: Request session.create failed with message:
SDK session authentication failed: Failed to fetch Copilot user info: 401 Unauthorized: {"message":"Bad credentials"}
Confirmed (via process-level environment variable injection of GITHUB_HOST, GH_HOST, GITHUB_API_URL set to the tenant host, merged with the full parent environment rather than replacing it) that this call always targets https://api.github.com/copilot_internal/user, regardless of these variables. The token is a valid tenant token — it simply cannot be valid against api.github.com.
SessionConfig.GitHubTokenProvider: CreateSessionAsync throws with a local, pre-network validation error instead:
ErrorType=query Message=Execution failed: InvalidArg, No GitHub OAuth token or Copilot HMAC key provided
No outbound network call is observed for this path at all — the provided callback does not appear to be invoked before this error fires, regardless of CopilotClientMode.
Expected behavior
Per the SDK's own documentation, both SessionConfig.GitHubToken and SessionConfig.GitHubTokenProvider should let the runtime resolve the Copilot API base URL from the tenant associated with the supplied token (api.<tenant>.ghe.com / copilot-api.<tenant>.ghe.com), exactly as the ambient UseLoggedInUser = true path already does successfully for the same tenant/token combination.
What we ruled out
| Attempt | Result |
|---|---|
UseLoggedInUser = true (ambient identity, same tenant/account) |
Works — proves token/tenant/account are valid |
GITHUB_HOST / GH_HOST / GITHUB_API_URL env vars on the client process (merged with the full parent environment, not replacing it) |
No effect — still routes to api.github.com |
CopilotClientMode.Empty with BaseDirectory and AvailableTools set (both required, undocumented prerequisites discovered via trial/error) |
Session construction succeeds, but the auth call still mis-routes |
Different token sources (OAuth Authorization Code flow token, copilot-cli token extracted from Windows Credential Manager) |
Identical failure for both |
Additional context
Same host mis-routing defect class as #76 (fixed in v0.0.332) and #4527 (fixed, but only for the CLI -p prompt-mode code path). Possibly related to #4378 (MCP registry policy fetch, same GHEC-DR fallback pattern, different subsystem). This report is scoped specifically to the GitHub.Copilot.SDK .NET session-level credential APIs (SessionConfig.GitHubToken, SessionConfig.GitHubTokenProvider), which does not appear to be covered by any of the above fixes as of CLI 1.0.84-5 (bundled with SDK 1.0.15-preview.0).
This blocks the documented multi-user/server integration pattern (one shared runtime serving many end users, each with their own GitHub Copilot entitlement) for any GHEC Data Residency tenant — the SDK's flagship use case for SessionConfig.GitHubToken/GitHubTokenProvider.
Suggested fix: apply the same per-subscription/tenant endpoint resolution used by the ambient (UseLoggedInUser) path to the SessionConfig.GitHubToken and GitHubTokenProvider code paths — likely by deriving the tenant host from the token itself rather than defaulting to api.github.com.
Affected version
GitHub.Copilot.SDK (.NET NuGet package): 1.0.15-preview.0
Bundled/pinned Copilot CLI runtime: 1.0.84-5 (older than 1.0.85, referenced as fixing #4527)
Environment
- Host tenant type: GitHub Enterprise Cloud with Data Residency + Enterprise Managed Users (confirmed via
"plan":{"name":"emu_user"}onGET https://api.<tenant>.ghe.com/user) - Operating system: Windows 11
- CPU architecture: x86_64 (AMD64)
- .NET: 8 (SDK preview 11.0.100-rc.1.26425.128)
- Auth method: OAuth Authorization Code flow token (separate from
copilot login)
Affected version
No response
Steps to reproduce the behavior
-
On a GHEC Data Residency tenant (
<tenant>.ghe.com), obtain a validgho_user access token via a standard OAuth Authorization Code flow (notcopilot login). -
Create a
CopilotClientexplicitly configured for the documented multi-user/server pattern, with no client-level GitHub credential:var client = new CopilotClient(new CopilotClientOptions { Mode = CopilotClientMode.Empty, BaseDirectory = "<isolated temp dir>", UseLoggedInUser = false }); await client.StartAsync(); -
Create a session passing the token via the stable
SessionConfig.GitHubTokenfield:var session = await client.CreateSessionAsync(new SessionConfig { Model = "gpt-5", GitHubToken = userToken, AvailableTools = new ToolSet().AddBuiltIn(BuiltInTools.Isolated) }); -
Observe
CreateSessionAsyncthrow:SDK session authentication failed: Failed to fetch Copilot user info: 401 Unauthorized: {"message":"Bad credentials"} -
Repeat step 3 using
SessionConfig.GitHubTokenProviderinstead:var session = await client.CreateSessionAsync(new SessionConfig { Model = "gpt-5", GitHubTokenProvider = args => Task.FromResult(GitHubTokenProviderResult.FromToken(new GitHubToken { AccessToken = userToken, ExpiresIn = 8 * 60 * 60 })), AvailableTools = new ToolSet().AddBuiltIn(BuiltInTools.Isolated) }); -
Observe a different, local (pre-network) failure instead:
Execution failed: InvalidArg, No GitHub OAuth token or Copilot HMAC key provided -
Confirm the same token/tenant/account works correctly via the ambient path, ruling out a token or tenant configuration issue:
var client = new CopilotClient(new CopilotClientOptions { UseLoggedInUser = true }); -
(Optional, to rule out host-resolution env vars) Re-run step 2–4 with
GITHUB_HOST,GH_HOST, andGITHUB_API_URLset to the tenant host inCopilotClientOptions.Environment(merged with the full parent environment). Observe identical failure — the runtime still callsapi.github.comfor theCopilot user infocheck.
Expected behavior
Both SessionConfig.GitHubToken and SessionConfig.GitHubTokenProvider should let the runtime resolve the Copilot API base URL from the tenant associated with the supplied token (api.<tenant>.ghe.com / copilot-api.<tenant>.ghe.com), exactly as the ambient UseLoggedInUser = true path already does successfully for the same tenant/token combination — session creation should succeed and the prompt should return a normal assistant response, without ever contacting api.github.com.
Secondarily:
SessionConfig.GitHubTokenProvidershould actually invoke the supplied callback (with aGitHubTokenProviderArgs.Hostreflecting the resolved tenant host) before failing, rather than failing locally with a generic "no token provided" error that never reaches the callback.- If the resolved token is rejected by the tenant's Copilot service, the error should surface the actual host and endpoint that was called (as already suggested for the CLI in #4527), instead of a generic
Bad credentialsmessage that gives no indication the wrong host was contacted.
Additional context
No response
- Langage dominant
- Shell
- Étoiles
- 11.2k
- Forks
- 1.9k
- Merge moyen
- 14 h 16 min
- PR mergées (30 j)
- 6
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de github/copilot-cli
-
triage
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
github/copilot-cli#4932 ·
-
triage
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
github/copilot-cli#4909 ·
-
triage
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
github/copilot-cli#4906 ·
-
triage
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
github/copilot-cli#4848 ·
-
area:agents area:mcp
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
github/copilot-cli#4729 ·
Toutes les issues de github/copilot-cli
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
elastic/gradle-plugins#156 ·
-
Priority/High ready-for-agent Severity/Major Type/Bug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
-
comp/cli P3 type/docs
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
NousResearch/hermes-agent#119756 · 1 commentaire ·
-
comp: build/pipeline type: bug version: current (v17+)
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
angular/angularfire#3766 ·
-
out-of-date
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
CachyOS/CachyOS-PKGBUILDS#1903 ·