Microsoft Entra Agent ID
General

Call Microsoft Graph as a user with ASP.NET Core

In brief

A new Microsoft Entra Agent ID guide explains how an ASP.NET Core agent API uses Microsoft.Identity.Web and GraphServiceClient to call Graph for a signed-in user, including User.Read permissions, grants, endpoint configuration, and testing.

What Entra admins need to know

Administrators implementing this pattern must grant the agent identity the required delegated Graph permissions; client-to-agent consent alone does not provide Graph access.

This editorial summary was generated by AI from the documentation changes. Verify important details in the full Microsoft Learn article.

Documentation change

The comparison below shows only the changed extract. Use the full-page view for complete context.

new file mode 100644

title: Call Microsoft Graph as a user with ASP.NET Core description: Configure GraphServiceClient to call Microsoft Graph on behalf of a signed-in user through an agent identity. titleSuffix: Microsoft Entra Agent ID ms.topic: how-to ms.date: 11/05/2026 ai-usage: ai-assisted ms.reviewer: dastrock, jomondi #customer-intent: As a developer building an interactive cloud agent, I want to call Microsoft Graph on behalf of the signed-in user.

Call Microsoft Graph as a user with ASP.NET Core

Use Microsoft Graph to read the signed-in user's profile through your agent API.

In this article, the client calls the agent with an agent API token. Microsoft.Identity.Web exchanges it for a delegated Graph token without starting another interactive sign-in.

Prerequisites

Add Microsoft Graph

Install the integration package:

dotnet add package Microsoft.Identity.Web.GraphServiceClient

Register GraphServiceClient with the services configured in the parent article. For this example, call builder.Services.AddMicrosoftGraph with options.BaseUrl set to https://graph.microsoft.com/v1.0 and options.Scopes set to ["User.Read"]. This configures downstream Graph access, not the incoming agent API's permission.

Place this registration before builder.Build() in the agent API's Program.cs.

builder.Services.AddMicrosoftGraph(options =>
{
    options.BaseUrl = "https://graph.microsoft.com/v1.0";
    options.Scopes = ["User.Read"];
});

Call Microsoft Graph

GraphServiceClient uses the authenticated user assertion from the request and the configured shared client ID. Don't set RequestAppToken or an Agent ID override; this call uses ordinary delegated access.

Require authentication and verify the incoming access_agent scope before calling graphClient.Me.GetAsync(). The incoming token is for the agent API; Microsoft.Identity.Web acquires a different token for Microsoft Graph.

Merge the following using directives with those at the top of Program.cs, and place the endpoint before its single app.Run(). You can omit the custom API endpoint from the parent walkthrough.

using Microsoft.Graph;
using Microsoft.Identity.Web;
using Microsoft.Identity.Web.Resource;

app.MapGet("/graph-me", async (
    HttpContext context,
    GraphServiceClient graphClient) =>
{
    context.VerifyUserHasAnyAcceptedScope("access_agent");

    var user = await graphClient.Me.GetAsync();

    return Results.Ok(new
    {
        user?.Id,
        user?.DisplayName,
        user?.UserPrincipalName
    });
})
.RequireAuthorization();

The example requires User.Read. Add only the delegated permissions required by your Graph calls.

Verify the Graph call

Start the agent API with dotnet run --urls https://localhost:5001. In the local test client, change only the request URL to https://localhost:5001/graph-me; keep the agent API scope. Sign in as the user covered by both grants. Expect HTTP 200 and that user's profile, with id matching the object ID returned by /whoami.

A call without a token must return 401. If token acquisition reports missing consent, check the agent-to-Graph grant separately from the client's access to the agent. OBO can't display an interactive consent prompt. Stop the projects when finished and follow the steps to clean up the local agent authentication test for test-only resources.

Related content

Daily Entra.News

Get daily email updates

Get a concise summary of the latest Microsoft Entra updates delivered straight to your inbox.

Loading the secure signup form…