Skip to content

.NET: .NET: fix: Forward x-agent-user-id to toolbox proxy to resolve OAuth consent binding #8379 - #8561

Open
sunoj (sun-9545sunoj) wants to merge 4 commits into
microsoft:mainfrom
sun-9545sunoj:fix-hosted-agent-consent-link
Open

sunoj (sun-9545sunoj) wants to merge 4 commits into
microsoft:mainfrom
sun-9545sunoj:fix-hosted-agent-consent-link

Conversation

@sun-9545sunoj

Copy link
Copy Markdown

Motivation & Context

Fixes #8379                                                                                                  
                                                                                                             
When a hosted agent uses a pre-registered toolbox with a per-user OAuth MCP connection, the consent link in  

its oauth_consent_request was being bound to the container's managed identity rather than the calling user.
This caused sign-in to fail with Code <id> not found on the callback.

### Description & Review Guide                                                                               
                                                                                                             
- **What are the major changes?**                                                                            
  - Updated `HostedCallContext` to capture and store the `UserId` (the `UserIdKey` from `PlatformContext`) in

addition to CallId.
- Updated AgentFrameworkResponseHandler to re-apply HostedCallContext.UserId alongside CallId at
yield boundaries, ensuring the user ID is correctly scoped per request.
- Updated FoundryToolboxBearerTokenHandler to forward the x-agent-user-id HTTP header during egress to
the toolbox proxy, mirroring the existing behavior for x-agent-foundry-call-id.
- What is the impact of these changes?
- The toolbox proxy will now resolve the server-side caller context for the human user rather than
defaulting to the container's Azure Managed Identity. This guarantees that the OAuth consent link generated
(CONSENT_REQUIRED) correctly binds to the caller, allowing the sign-in and subsequent tools lookup to succeed.
- What do you want reviewers to focus on?
- Verify that the yield boundaries and egress interception in AgentFrameworkResponseHandler properly
reapply the UserId.

### Related Issue                                                                                            
                                                                                                             
Fixes #8379                                                                                                  
                                                                                                             
### Contribution Checklist                                                                                   
                                                                                                             
- [x] The code builds clean without any errors or warnings                                                   
- [x] All unit tests pass, and I have added new tests where possible                                         
- [x] The PR follows the [Contribution Guidelines](https://github.com/microsoft/agent-                       

framework/blob/main/CONTRIBUTING.md)
- [x] This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
- [x] This is not a breaking change.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@agent-framework-automation agent-framework-automation Bot added the .NET Usage: [Issues, PRs], Target: .Net label Sep 20, 2026
@github-actions github-actions Bot changed the title .NET: fix: Forward x-agent-user-id to toolbox proxy to resolve OAuth consent binding #8379 .NET: .NET: fix: Forward x-agent-user-id to toolbox proxy to resolve OAuth consent binding #8379 Sep 20, 2026
@sun-9545sunoj

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants