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.
Read blob data with the agent's own identity, without a signed-in user's delegated access. Azure services authorize 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 SDK 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-datablob container. Replace<storage-account>in the example with the account name. - An Azure data-plane role assignment for the agent identity's object ID on that container or account, not for the blueprint or its managed identity credential.
Install the integration package and Blob Storage SDK from the agent project's directory:
dotnet add package Microsoft.Identity.Web.Azure
dotnet add package Azure.Storage.Blobs
Configure the token credential
Register MicrosoftIdentityTokenCredential with dependency injection:
Add the following registration before builder.Build() in Program.cs, and merge the using directive with those at the top of the 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.
Warning
Client secrets shouldn't be used as client credentials in production environments for agent identity blueprints due to security risks. Instead, use more secure authentication methods such as federated identity credentials (FIC) with managed identities or client certificates. These methods provide enhanced security by eliminating the need to store sensitive secrets directly within your application configuration.
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 AgentStorageService
{
private readonly MicrosoftIdentityTokenCredential _credential;
public AgentStorageService(MicrosoftIdentityTokenCredential credential)
{
_credential = credential;
}
public async Task<IReadOnlyList<string>> ListBlobsAsync()
{
_credential.Options.RequestAppToken = true;
var serviceClient = new BlobServiceClient(
new Uri("https://<storage-account>.blob.core.windows.net"),
_credential);
var container = serviceClient.GetBlobContainerClient("agent-data");
var names = new List<string>();
await foreach (var blob in container.GetBlobsAsync())
{
names.Add(blob.Name);
}
return names;
}
}
RequestAppToken = true selects autonomous, app-only access. For a user-delegated Azure call, use Call an Azure service as a user.
The Agent ID needs an appropriate data-plane role, such as Storage Blob Data Reader. A management-plane role such as Reader doesn't grant access to blob 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 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
Authenticate users to the agent API