-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Description
Issue: Authorization Header Not Passed to Agent Framework Hosting Adapter
We are hosting an Agent in Foundry using the Hosted Agent model. The implementation follows the sample at:
[foundry-samples/samples/python/hosted-agents/agent-framework/agent-with-foundry-tools/main.py](https://github.com/microsoft-foundry/foundry-samples/blob/main/samples/python/hosted-agents/agent-framework/agent-with-foundry-tools/main.py), which relies on the HostingAdapter from_agent_framework.
Currently, I’ve observed that metadata sent via the /responses API is surfaced in AgentContext.agent._request_headers. However, this does not include the OAuth token provided in the Authorization header.
This omission is problematic because:
- Our Agent needs to call downstream APIs that are OAuth-protected and require user context.
- The ideal flow is to obtain an OBO (On-Behalf-Of) token from the original incoming token.
- Without access to the
Authorizationheader, OBO cannot be performed, which makes Agents unsuitable for production scenarios requiring user-context delegation.
A possible workaround is to ask callers to include the OAuth token in the /responses metadata field. However, this is non-standard and insecure, since callers could spoof arbitrary tokens.
Proposed Fix
The Agent Framework Hosting Adapter should be updated to forward the Authorization header token into the Agent middleware. This would enable Agents to:
- Retrieve OBO tokens from the original incoming token.
- Use those OBO tokens to securely call downstream APIs and MCP servers.
Code Sample
You can take this codebase - https://github.com/microsoft-foundry/foundry-samples/blob/main/samples/python/hosted-agents/agent-framework/agent-with-foundry-tools/main.py
And this middleware codebase where Authorization header is not injected - https://github.com/microsoft/agent-framework/blob/fcdaaff9cd32a410c51fb0bfa0080d277cbcab81/python/samples/02-agents/middleware/agent_and_run_level_middleware.pyError Messages / Stack Traces
Unable to extract Authorization header.Package Versions
Latest
Python Version
Python 3.12
Additional Context
No response