Repository navigation
agentHost: forward the authentication ID token and learn the tenant - #350464
Merged
Merged
Conversation
Forward the Microsoft session's ID token on authenticate, using the optional idToken field from microsoft/agent-host-protocol#631. The host keeps it with the accepted credential, replays it, and redacts it from AHP logs. The Entra bridge reads the unverified tid claim from the first ID token sent for the account and keeps it with the account. Nothing is handed to the runtime yet: the identity result that carries the tenant is left as a TODO until the SDK accepts it. Sync the protocol copy with idToken as a targeted backport on the current pin. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
ID tokens remain exposed to relays on sealed connections, while credential caching and lookup can prevent newly available identity claims from reaching or updating the host.
3 open issues
What changed in this PR
Extends Agent Host authentication to carry optional ID tokens and retain the Microsoft account’s tenant for future SDK support. The tenant is not yet returned to the runtime.
Changes:
- Adds client forwarding and host validation, storage, and replay of ID tokens.
- Reads and retains the first usable tenant claim for the selected account.
- Updates log redaction, regression tests, and protocol-backport documentation.
| File | Description |
|---|---|
src/vs/workbench/contrib/chat/test/browser/agentSessions/copilotEntraAuthentication.test.ts |
Tests ID-token forwarding from authentication sessions. |
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostAuth.ts |
Adds ID tokens to client authentication requests. |
src/vs/platform/agentHost/test/node/copilotEntraAuthentication.test.ts |
Tests validation, storage, replay, and tenant retention. |
src/vs/platform/agentHost/test/common/ahpJsonlLogger.test.ts |
Tests ID-token redaction with pre-redacted access tokens. |
src/vs/platform/agentHost/node/copilot/copilotEntraAuthentication.ts |
Learns and retains the account’s tenant claim. |
src/vs/platform/agentHost/node/agentHostAuthenticationService.ts |
Validates, stores, and replays ID tokens. |
src/vs/platform/agentHost/common/state/protocol/common/commands.ts |
Adds the optional protocol idToken field. |
src/vs/platform/agentHost/common/state/AGENTS.md |
Documents the targeted protocol backport. |
src/vs/platform/agentHost/common/ahpJsonlLogger.ts |
Redacts ID tokens independently of access tokens. |
src/vs/platform/agentHost/common/agent.ts |
Extends the internal authentication contract. |
src/vs/platform/agentHost/AGENTS.md |
Documents ID-token handling and tenant retention. |
Review effort: Balanced
…epted credential Drop the ID token wherever the access token is sealed, since only the token can be sealed and a relay would otherwise read its claims. Learn the tenant from the discovery credential that was just accepted, not from an older credential stored under the advertised scopes. Include the ID token in the client's forwarded-credential key, so one that becomes available for an unchanged access token still reaches the host. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Stop dropping the ID token where the access token is sealed. An optional field that is silently omitted on one kind of connection is hard to notice, and the relay already carries the session's content in clear; the ID token is identity, not access. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move authenticate redaction into one function so the log replacer does not grow, share the nonempty-string check between accountId and idToken, and store the ID token the same way as the account ID. Stop storing the ID token on host execution credentials, where nothing can read it, and keep the authority type private to the bridge. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
TylerLeonhardt
marked this pull request as ready for review
November 26, 2026 00:21
TylerLeonhardt
enabled auto-merge
November 26, 2026 00:22
Ross Wollman (rwoll)
approved these changes
Nov 26, 2026
Dmitriy Vasyura (dmitrivMS)
approved these changes
Nov 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Problem
The Copilot agent host knows the signed-in Microsoft account only by the opaque
authenticate.accountId. An upcoming Copilot SDK contract (github/copilot-agent-runtime#34048) requires the host to also return the account's Entra tenant when the runtime asks for its identity. The host has no way to learn it: the access token is opaque to it, andaccountIdmust not be parsed.Changes
This uses the optional
AuthenticateParams.idTokenadded in microsoft/agent-host-protocol#631, so no private metadata is involved.authenticatewhenever the session has one. On relayed connections (Web PubSub and Mission Control) onlytokenis sealed, so the ID token crosses the relay in clear. That is deliberate: the relay already carries the session's content in clear, the ID token grants no access, and an optional field omitted on one kind of connection would be hard to notice.idToken, keeps it with the accepted credential, replays it to providers, and exposes it ongetAuthCredential.idToken. It needs its own check because the relay transport pre-redactstoken, which made the logger skip the entry.tidclaim from the first ID token sent with a discovery credential and keeps it with the account. A later credential without an ID token does not lose it, and a differenttidfor the same account does not replace it.idTokenis synced as a targeted backport on the current pin (1928cd4e), recorded incommon/state/AGENTS.md. A full sync to AHPmainbrings unrelated protocol changes that need their own adoption.Not in this PR
The tenant is not handed to the runtime. The current SDK (2.0.3) has no
tenantIdon the identity result, so the return that carries it is a commented line under aTODOinresolveEntraIdentity. Adopting it also means updating the identity expectations in the Entra and Copilot agent tests, whose fixtures send no ID token.Once that line is live, a client that sends no ID token will not be able to sign in to the Microsoft path. Until then, behaviour without an ID token is unchanged.
How to test
./scripts/test.sh --reporter dot --run src/vs/platform/agentHost/test/electron-browser/agentHostProtocolClient.test.ts --run src/vs/platform/agentHost/test/node/copilotEntraAuthentication.test.ts --run src/vs/platform/agentHost/test/node/copilotAccountService.test.ts --run src/vs/platform/agentHost/test/common/ahpJsonlLogger.test.ts --run src/vs/platform/agentHost/test/node/agentHostAuthenticationScope.test.ts --run src/vs/workbench/contrib/chat/test/browser/agentSessions/copilotEntraAuthentication.test.ts --run src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostAuth.test.ts— passed, 767 tests../scripts/test.sh --reporter dot --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts --grep "Microsoft|Entra"— passed, 31 tests.pnpm run typecheck-client— passed.pnpm run oxlinton the changed TypeScript files — passed.Live check on a source build of this branch (SDK 2.0.3) with
chat.agentHost.copilot.m365.enabledon: after "Continue with Microsoft", sign-in completed and the host listed its models. Logpoints in the agent host showed the discoveryauthenticaterequest carrying an ID token, the bridge reading itstid, and the stored account holding that tenant each time the runtime asked for the identity. A later discovery credential for the same account kept the tenant.An earlier run of the first commit, on SDK 2.0.2, captured the tenant the same way, but sign-in then failed in service discovery with "The runtime returned an unsupported Microsoft service choice". That did not reproduce on this branch. I did not isolate the cause.
Not checked live: a relayed (Mission Control) connection.
Not run: the full unit, integration and smoke suites.