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.
Use application permissions when an autonomous agent calls Microsoft Graph without a signed-in user.
Prerequisites
- Completion of Configure the Auth SDK sidecar, including the agent's registration and client ID.
- Administrator consent for the Microsoft Graph application permission
Organization.Read.Allon the Agent ID.
Configure access
- Grant the Microsoft Graph application permission
Organization.Read.Allto the Agent ID and have an administrator consent to it. - Configure a sidecar API, such as
graph-app, with the Microsoft Graph base URL andhttps://graph.microsoft.com/.defaultscope.
Application permissions can provide broad tenant access. Grant only the permissions required by the scenario.
Configure the sidecar
Add an app-only profile for Microsoft Graph with the configured client ID:
{
"DownstreamApis": {
"graph-app": {
"BaseUrl": "https://graph.microsoft.com/v1.0/",
"Scopes": [
"https://graph.microsoft.com/.default"
],
"RequestAppToken": true
}
}
}
For the blueprint identity, credential, and container configuration, see Configure the Auth SDK sidecar.
Read the organization with Microsoft Graph
This example uses Node.js 18 or later and the built-in Fetch API. Run it from the agent; don't pass a user token or identity override.
The sidecar request uses the configured app-only profile:
GET /AuthorizationHeaderUnauthenticated/graph-app
async function getOrganizationAsAgent() {
const tokenResponse = await fetch("http://localhost:5000/AuthorizationHeaderUnauthenticated/graph-app");
if (!tokenResponse.ok) {
throw new Error(`Sidecar token request failed (HTTP ${tokenResponse.status}); check the profile, credential, and admin consent.`);
}
const { authorizationHeader } = await tokenResponse.json();
const response = await fetch("https://graph.microsoft.com/v1.0/organization?$select=id,displayName", {
headers: { Authorization: authorizationHeader }
});
if (!response.ok) {
throw new Error(`Microsoft Graph returned HTTP ${response.status}; verify Organization.Read.All is consented for the Agent ID.`);
}
return response.json();
}
Call getOrganizationAsAgent() from the agent. A successful request returns 200 OK and one organization object containing its ID and display name. If Graph returns 403, verify that Organization.Read.All is granted to the Agent ID and admin consent is current; then retry. If the sidecar returns 401, check token acquisition and the graph-app profile. Don't log the authorization header. See the List organizations API for its application permission requirements.
Next step
Authenticate users to the agent