A fully managed platform in Microsoft Foundry for hosting, scaling, and securing AI agents built with any supported framework or model
Hello @Cristopher Coronado
Welcome to Microsoft Q&A .Thank you for reaching out to us.
The scenario and observations align closely with the current behavior of identity handling in Azure AI Foundry. The following consolidated response addresses each question and provides practical supported guidance.
- OAuth Identity Passthrough with Hosted Agents OAuth Identity Passthrough is a tool-level capability configured on MCP connections and executed by the Agent Service to preserve user identity during tool invocation. However, for code-first Hosted Agents:
- No documented API exists to bind agent code to a project connection programmatically
- OAuth flows are handled externally by the service layer
- User tokens are not exposed within container runtime
- Identity Behavior in Hosted Agents Hosted Agents execute using a platform-managed agent identity by default.
- All outbound calls from container code use this identity
- Token acquisition and exchange are handled internally by the service
- User identity is only applied when tool execution goes through configured passthrough flows
- Consent Flow (oauth_consent_request) Consent handling is platform-driven, not programmable.
- No SDK/API is available to trigger consent from container code
- Hosted Agents cannot emit or control oauth_consent_request
- Consent experience is surfaced by the service during supported tool invocation flows
- On-Behalf-Of (OBO) and Token Exchange Token exchange during tool invocation is handled internally, and no runtime API is available for custom OBO scenarios. Current behavior:
- Tokens issued for one audience (e.g., platform endpoints) cannot be exchanged for custom APIs (
api://<app-id>) - No supported mechanism exists to perform manual token exchange inside Hosted Agents
- Platform-managed identity does not support confidential client configuration
- Decode token and verify:
-
aud(audience) -
oid/upn - Ensure MCP server expects the correct audience:
api://<app-id>
- Azure Monitor
- Entra ID sign-in logs
- Tokens issued for one audience (e.g., platform endpoints) cannot be exchanged for custom APIs (
Please check if the following approaches help
-
- Configure OAuth Identity Passthrough on MCP tools
- Allow the service to manage:
- Consent
- Token acquisition and refresh
- Passing user context downstream
- Hybrid pattern - balanced approach - Combine platform-managed flow with Hosted Agent execution Authentication flow - tool invocation with user identity Hosted Agent - orchestration and business logic
- Alternative approaches - custom design Token broker service
- Validate incoming identity
- Issue tokens aligned with downstream API
- Requires custom security design
- Managed identity + user context
- Authenticate using agent identity
- Pass user context via headers or signed payload
- Enforce authorization at downstream service
The following references might be helpful , please check them out
- Set Up MCP Server Authentication - Microsoft Foundry | Microsoft Learn
- Agent identity concepts in Microsoft Foundry - Microsoft Foundry | Microsoft Learn
- Connect an MCP server on Azure Functions to Foundry Agent Service | Microsoft Learn
- Microsoft Entra Connect: Troubleshoot Pass-through Authentication - Microsoft Entra ID | Microsoft Learn
- Microsoft identity platform and OAuth2.0 On-Behalf-Of flow - Microsoft identity platform | Microsoft Learn
Thank you