Create Delete Agent Identities
In brief
The documentation updates the C# sample’s imports, endpoint structure, downstream API call, and model declarations to provide valid create-agent-identity code.
What Entra admins need to know
Administrators using this sample should review the updated code. No Entra service change or administrative action is indicated.
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.
The code for the ASP.NET Core app (Program.cs) is the following example:
using System.Text.Json.Serialization;
using Microsoft.Identity.Abstractions;
using Microsoft.Identity.Web;
using Microsoft.Identity.Web.Resource;
using Microsoft.IdentityModel.S2S.Extensions.AspNetCore;
using MyAgent;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddMicrosoftIdentityWebApiAuthentication(builder.Configuration)
.EnableTokenAcquisitionToCallDownstreamApi();
builder.Services.AddInMemoryTokenCaches();
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
public class AgentIdentity
{
[JsonPropertyName("@odata.type")]
public string @odata_type { get; set; } = "#Microsoft.Graph.AgentIdentity";
[JsonPropertyName("displayName")]
public string? displayName { get; set; }
[JsonPropertyName("agentIdentityBlueprintId")]
public string? agentIdentityBlueprintId { get; set; }
[JsonPropertyName("id")]
public string? id { get; set; }
[JsonPropertyName("[email protected]")]
public string[]? sponsorsOdataBind { get; set; }
[JsonPropertyName("[email protected]")]
public string[]? ownersOdataBind { get; set; }
}
// Create an Agent identity
app.MapGet("/create-agent-identity", async (HttpContext httpContext) =>
{
try
{
// Get the service to call the downstream API (preconfigured in the appsettings.json file)
IDownstreamApi downstreamApi = httpContext.RequestServices.GetRequiredService<IDownstreamApi>();
// Call the downstream API with a POST request to create an Agent Identity
var jsonResult = await downstreamApi.PostForAppAsync<AgentIdentity, AgentIdentity>(
"agent-identity",
new AgentIdentity
{
displayName = "My agent identity",
agentIdentityBlueprintId = "<my-agent-blueprint-id>",
sponsorsOdataBind = new []new[] { "https://graph.microsoft.com/v1.0/users/<id>" }
}
);});
return jsonResult?.id;
}
catch (Exception ex)
{
return ex.Message;
}
});
app.Run();
// Type declarations must follow the top-level statements.
public class AgentIdentity
{
[JsonPropertyName("@odata.type")]
public string @odata_type { get; set; } = "#Microsoft.Graph.AgentIdentity";
[JsonPropertyName("displayName")]
public string? displayName { get; set; }
[JsonPropertyName("agentIdentityBlueprintId")]
public string? agentIdentityBlueprintId { get; set; }
[JsonPropertyName("id")]
public string? id { get; set; }
[JsonPropertyName("[email protected]")]
public string[]? sponsorsOdataBind { get; set; }
[JsonPropertyName("[email protected]")]
public string[]? ownersOdataBind { get; set; }
}
options.RelativePath += $"/{id}"; // Specify the ID of the agent identity to delete
});
return jsonResult;
});
---
@@ -156,16 +156,17 @@ To use *Microsoft.Identity.Web* to execute the Microsoft Graph API request to cr The code for the ASP.NET Core app (*Program.cs*) is the following example: ```csharp+using System.Text.Json.Serialization; using Microsoft.Identity.Abstractions;+using Microsoft.Identity.Web; using Microsoft.Identity.Web.Resource; using Microsoft.IdentityModel.S2S.Extensions.AspNetCore;-using MyAgent; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddMicrosoftIdentityWebApiAuthentication(builder.Configuration)- .EnableTokenAcquisitionToCallDownstreamApi();+ .EnableTokenAcquisitionToCallDownstreamApi(); builder.Services.AddInMemoryTokenCaches(); var app = builder.Build(); @@ -173,54 +174,54 @@ app.UseHttpsRedirection(); app.UseAuthentication(); app.UseAuthorization(); -public class AgentIdentity+// Create an Agent identity+app.MapGet("/create-agent-identity", async (HttpContext httpContext) => {- [JsonPropertyName("@odata.type")]- public string @odata_type { get; set; } = "#Microsoft.Graph.AgentIdentity";+ try+ {+ // Get the service to call the downstream API (preconfigured in the appsettings.json file)+ IDownstreamApi downstreamApi = httpContext.RequestServices.GetRequiredService<IDownstreamApi>();++ // Call the downstream API with a POST request to create an Agent Identity+ var jsonResult = await downstreamApi.PostForAppAsync<AgentIdentity, AgentIdentity>(+ "agent-identity",+ new AgentIdentity+ {+ displayName = "My agent identity",+ agentIdentityBlueprintId = "<my-agent-blueprint-id>",+ sponsorsOdataBind = new[] { "https://graph.microsoft.com/v1.0/users/<id>" }+ });+ return jsonResult?.id;+ }+ catch (Exception ex)+ {+ return ex.Message;+ }+}); - [JsonPropertyName("displayName")]- public string? displayName { get; set; }+app.Run(); - [JsonPropertyName("agentIdentityBlueprintId")]- public string? agentIdentityBlueprintId { get; set; }+// Type declarations must follow the top-level statements.+public class AgentIdentity+{+ [JsonPropertyName("@odata.type")]+ public string @odata_type { get; set; } = "#Microsoft.Graph.AgentIdentity"; - [JsonPropertyName("id")]- public string? id { get; set; }+ [JsonPropertyName("displayName")]+ public string? displayName { get; set; } - [JsonPropertyName("[email protected]")]- public string[]? sponsorsOdataBind { get; set; }+ [JsonPropertyName("agentIdentityBlueprintId")]+ public string? agentIdentityBlueprintId { get; set; } - [JsonPropertyName("[email protected]")]- public string[]? ownersOdataBind { get; set; }-}+ [JsonPropertyName("id")]+ public string? id { get; set; } -// Create an Agent identity-app.MapGet("/create-agent-identity", async (HttpContext httpContext) =>-{- try- {- // Get the service to call the downstream API (preconfigured in the appsettings.json file)- IDownstreamApi downstreamApi = httpContext.RequestServices.GetRequiredService<IDownstreamApi>();-- // Call the downstream API with a POST request to create an Agent Identity- var jsonResult = await downstreamApi.PostForAppAsync<AgentIdentity, AgentIdentity>(- "agent-identity",- new AgentIdentity {- displayName = "My agent identity",- agentIdentityBlueprintId = "<my-agent-blueprint-id>",- sponsorsOdataBind = new [] { "https://graph.microsoft.com/v1.0/users/<id>" }- }- );- return jsonResult?.id;- }- catch (Exception ex)- {- return ex.Message;- }+ [JsonPropertyName("[email protected]")]+ public string[]? sponsorsOdataBind { get; set; } -})--app.Run();+ [JsonPropertyName("[email protected]")]+ public string[]? ownersOdataBind { get; set; }+} ``` ---@@ -256,7 +257,7 @@ app.MapGet("/delete-agent-identity", async (HttpContext httpContext, string id) options.RelativePath += $"/{id}"; // Specify the ID of the agent identity to delete }); return jsonResult;-})+}); ``` --- 