Microsoft Entra Agent ID
Security

Call Azure services from an agent using .NET Azure SDK

In brief

The article now shows Blob Storage access using MicrosoftIdentityTokenCredential and app-only tokens. It specifies that Azure RBAC roles must target the agent identity’s object ID at the container or account scope, rather than the blueprint or its managed identity credential.

What Entra admins need to know

Ensure the agent identity has the required minimum data-plane role assignment at the appropriate scope.

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.

Call Azure services from your agent using .NET Azure SDK

This article guides you on how to callRead blob data with the agent's own identity, without a signed-in user's delegated access. Azure services from your agent. To authenticateauthorize the Agent ID through Azure role-based access control (Azure RBAC).

In this article, you adapt an ASP.NET Core agent's token acquisition to Azure services such asSDK clients. Assign the minimum role at the narrowest resource scope.

Prerequisites

  • The blueprint credential and ASP.NET Core services, including token acquisition. Reuse the local certificate configuration when running on a workstation. This example doesn't require the custom API's app role or consent grant.
  • An existing storage account and an agent-data blob container. Replace <storage-account> in the example with the account name.
  • An Azure Storagedata-plane role assignment for the agent identity's object ID on that container or Azure Key Vault using agent identities, useaccount, not for the MicrosoftIdentityTokenCredential class from Microsoft.Identity.Web.Azure. The MicrosoftIdentityTokenCredential class implements Azure SDK's TokenCredential interface, enabling seamless integration between Microsoft.Identity.Web and Azure SDK clients.

    [!INCLUDE Common call API content]

    Implementation steps

    1. blueprint or its managed identity credential.

Install the Azure integration package and Blob Storage SDK from the Microsoft.Identity.Web.AgentIdentities package to add support for agent identities.project's directory:

dotnet add package Microsoft.Identity.Web.Azure
dotnet add package Microsoft.Identity.Web.AgentIdentities
  • Install the Azure SDK package you want to use, for example, Azure Storage:

    dotnet add package Azure.Storage.Blobs
    
  • Configure your services to add Azurethe token credential support:

    Register MicrosoftIdentityTokenCredential with dependency injection:

    using Microsoft.AspNetCore.Authentication.OpenIdConnect;
    using Microsoft.Identity.Web;
    
    var builder = WebApplication.CreateBuilder(args);
    
    // 

    Add authentication builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme) .AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd")) .EnableTokenAcquisitionToCallDownstreamApi() .AddInMemoryTokenCaches(); // Add Azure token credential support builder.Services.AddMicrosoftIdentityAzureTokenCredential(); builder.Services.AddControllersWithViews(); var app = the following registration before builder.Build(); app.UseAuthentication(); app.UseAuthorization(); app.MapControllers(); app.Run();

  • Configure Azure token credential options in appsettings.json

    [!INCLUDE Dont use secrets]

    {
      "AzureAd": {
        "Instance": "https://login.microsoftonline.com/"Program.cs, "TenantId": "<your-tenant-id>",
        "ClientId": "<agent-blueprint-id>",
    
       // Other client credentials available. See <https://aka.ms/ms-id-web/client-credentials>
        "ClientCredentials": [
          {
            "SourceType": "ClientSecret",
            "ClientSecret": "your-client-secret"
          }
        ]
      }
    }
    
  • Acquire a token credential from the service provider and use it with Azure SDK clients.

    1. For agent identities, you can acquire either an app only token (autonomous agents) or an on-behalf of user token (interactive agents) by usingmerge the WithAgentIdentityusing method. For app only tokens, setdirective with those at the RequestAppToken property to true. For delegated on-behalftop of user tokens, don't set the RequestAppToken property or explicitly set it to false.file.

      using Microsoft.Identity.Web;
      
      builder.Services.AddMicrosoftIdentityAzureTokenCredential();
      

      The credential uses the Microsoft.Identity.Web configuration established in the parent journey. Use a managed identity federated credential in hosted environments.

      [!INCLUDE Dont use secrets]

      Call Azure Blob Storage as the agent

      Inject MicrosoftIdentityTokenCredential and request an app-only token with the shared client ID configured in the parent journey:

      The following is a service component, not a complete Program.cs. Put the class in AgentStorageService.cs, register it with builder.Services.AddScoped<AgentStorageService>() before builder.Build(), and invoke ListBlobsAsync() from an authorized application operation. Preserve the parent journey's AgentUser policy on any endpoint that triggers this app-only operation.

      using Azure.Storage.Blobs;
      using Microsoft.Identity.Web;
      
      public sealed class AgentServiceAgentStorageService
      {
          private readonly MicrosoftIdentityTokenCredential _credential;
      
          public AgentService(AgentStorageService(MicrosoftIdentityTokenCredential credential)
          {
              _credential = credential;
          }
      
          // Call Azure service with the agent identity for app only scenario
          public async Task<ListIReadOnlyList<string>> ListBlobsForAgentAppOnlyAsync(string agentIdentity)ListBlobsAsync()
          {
              // Configure for agent identity
              _credential.Options.WithAgentIdentity(agentIdentity);
              _credential.Options.RequestAppToken = true;
      
              var blobClientserviceClient = new BlobServiceClient(
                  new Uri("https://myaccount.<storage-account>.blob.core.windows.net"),
                  _credential);
              var container = blobClient.serviceClient.GetBlobContainerClient("agent-data");
              var blobsnames = new List<string>();
      
              await foreach (var blob in container.GetBlobsAsync())
              {
                  blobs.names.Add(blob.Name);
              }
      
              return blobs;
          }
      
          // Call Azure service with the agent identity for on-behalf of user scenario
          public async Task<List<string>> ListBlobsForAgentOnBehalfOfUserAsync(string agentIdentity)
          {
              // Configure for agent identity
              _credential.Options.WithAgentIdentity(agentIdentity);
              _credential.Options.RequestAppToken = false;
      
              var blobClient = new BlobServiceClient(
                  new Uri("https://myaccount.blob.core.windows.net"),
                  _credential);
      
              var container = blobClient.GetBlobContainerClient("agent-data");
              var blobs = new List<string>();
      
              await foreach (var blob in container.GetBlobsAsync())
              {
                  blobs.Add(blob.Name);
              }
      
              return blobs;names;
          }
      }
      
    2. You can also acquireRequestAppToken = true selects autonomous, app-only access. For a token foruser-delegated Azure call, use Call an Azure service as a user.

      The Agent ID needs an agentappropriate data-plane role, such as Storage Blob Data Reader. A management-plane role such as Reader doesn's user account. To do this, you can use either User Principal Name (UPN) or Object Identity (OID)t grant access to identifyblob data.

      Use the same credential with other Azure SDK clients, including Azure Key Vault clients. Replace the endpoint and role with the values required by the target service.

      For a container containing test blobs, ListBlobsAsync() should return their names; an empty container returns an empty list. A storage 403 requires checking the agent's user account.data-plane role and target resource separately from successful token acquisition. Don't grant a management-plane role to fix missing blob data access.

      Next step

      For object ID:Authenticate users to the agent API

      using Microsoft.Identity.Web;
      
      public class AgentService
      {
          private readonly MicrosoftIdentityTokenCredential _credential;
      
          public AgentService(MicrosoftIdentityTokenCredential credential)
          {
              _credential = credential;
          }
      
          // Use object ID to identify the agent's user account
          public async Task<List<string>> ListBlobsForAgentUserByOidAsync(string agentIdentity)
          {
              // Configure for agent identity
              string userOid = "user-object-id";
              _credential.Options.WithAgentUserIdentity(agentIdentity, userOid);
      
              var blobClient = new BlobServiceClient(
                  new Uri("https://myaccount.blob.core.windows.net"),
                  _credential);
      
              var container = blobClient.GetBlobContainerClient("agent-data");
              var blobs = new List<string>();
      
              await foreach (var blob in container.GetBlobsAsync())
              {
                  blobs.Add(blob.Name);
              }
      
              return blobs;
          }
      
          // Use UPN to identify the agent's user account
          public async Task<List<string>> ListBlobsForAgentUserByUpnAsync(string agentIdentity)
          {
              // Configure for agent identity
              string userUpn = "[email protected]";
      
              _credential.Options.WithAgentUserIdentity(agentIdentity, userUpn);
      
              var blobClient = new BlobServiceClient(
                  new Uri("https://myaccount.blob.core.windows.net"),
                  _credential);
      
              var container = blobClient.GetBlobContainerClient("agent-data");
              var blobs = new List<string>();
      
              await foreach (var blob in container.GetBlobsAsync())
              {
                  blobs.Add(blob.Name);
              }
      
              return blobs;
          }
      }
      
  • 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…