Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
After the runtime routes a user's request to an agent, the agent can call APIs for that user with the On-Behalf-Of (OBO) flow. Forward the user's token to the sidecar, and pass the routed agent's identity in the AgentIdentity parameter. The downstream token represents both the signed-in user and that agent.
Prerequisites
- Complete Authenticate users and route requests to agents in a fleet with the Auth SDK sidecar.
- Delegated permissions for the target API, granted to the agent identity or inherited from the blueprint.
Configure the sidecar
Add a delegated profile for each API to the runtime sidecar:
{
"Sidecar": {
"AllowOverrides": {
"GetAuthorizationHeader": true
}
},
"DownstreamApis": {
"custom-api-user": {
"BaseUrl": "https://api.contoso.com/",
"Scopes": [
"api://<custom-api-client-id>/<delegated-scope>"
]
}
}
}
Explicitly enable GetAuthorizationHeader as shown, even if you previously disabled overrides by following the single-instance setup. Otherwise the sidecar ignores AgentIdentity. Only trusted runtime code should select and send identity overrides.
Get a token for the signed-in user
After routing the request and confirming the user can access the agent, call the sidecar:
def authorization_header_for_user(
inbound_auth_header: str, agent_id: str, api_name: str
) -> str:
registration = directory.find(agent_id)
response = requests.get(
f"{SIDECAR_URL}/AuthorizationHeader/{api_name}",
params={"AgentIdentity": registration["agent_identity_id"]},
headers={"Authorization": inbound_auth_header},
timeout=5,
)
if response.status_code in (401, 403):
raise PermissionError("The sidecar rejected the user token or OBO request.")
response.raise_for_status()
return response.json()["authorizationHeader"]
inbound_auth_header = request.headers.get("Authorization")
authorize_agent_request(inbound_auth_header, agent_id)
api_response = requests.get(
"https://api.contoso.com/user-data",
headers={
"Authorization": authorization_header_for_user(
inbound_auth_header, agent_id, "custom-api-user"
)
},
timeout=10,
)
api_response.raise_for_status()
Always use the agent ID that passed the access check. If the runtime used a different agent's identity, the downstream API would see the wrong agent acting for the user. Don't send the inbound token directly to the downstream API, and don't log either authorization header.
Call specific resources
Use the scopes and endpoints from the linked resource articles, while keeping the fleet's blueprint client ID and override settings. The single-instance requests omit AgentIdentity. For each fleet resource request, call authorization_header_for_user or authorizationHeaderForUser to supply the routed agent identity and inbound user token.
| Resource | Guidance |
|---|---|
| Custom API | Call a custom API as a user |
| Azure services | Call Azure services as a user |
| Microsoft Graph | Call Microsoft Graph as a user |