이 문서에서는 에이전트에서 Azure 서비스를 호출하는 방법을 안내합니다. Azure Storage 또는 Azure Key Vault와 같은 서비스를 에이전트 ID로 인증을 수행하려면 MicrosoftIdentityTokenCredential 클래스에서 를 사용합니다.
MicrosoftIdentityTokenCredential 클래스는 Azure SDK의 TokenCredential 인터페이스를 구현하여 Microsoft.Identity.Web과 Azure SDK 클라이언트 간의 원활한 통합을 가능하게 합니다.
에이전트에서 API를 호출하려면 에이전트가 API에 자신을 인증하는 데 사용할 수 있는 액세스 토큰을 가져와야 합니다. Microsoft.Identity.Web SDK를 사용하는 것이 .NET의 웹 API를 호출하는 데 권장됩니다. 이 SDK는 토큰을 획득하고 유효성을 검사하는 프로세스를 간소화합니다. 다른 언어의 경우 에이전트 ID에 Microsoft Entra 에이전트 SDK를 사용합니다.
사전 요구 사항
- 대상 API를 호출할 수 있는 적절한 권한이 있는 에이전트 ID입니다. 대신 흐름을 위한 사용자 계정이 필요합니다.
- 대상 API를 호출할 수 있는 적절한 권한이 있는 에이전트의 사용자 계정입니다.
구현 단계
Azure 통합 패키지와 Microsoft.Identity.Web.AgentIdentities 패키지를 설치하여 에이전트 ID에 대한 지원을 추가합니다.
dotnet add package Microsoft.Identity.Web.Azure dotnet add package Microsoft.Identity.Web.AgentIdentities사용하려는 Azure SDK 패키지를 설치합니다(예: Azure Storage).
dotnet add package Azure.Storage.BlobsAzure 토큰 자격 증명 지원을 추가하도록 서비스를 구성합니다.
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 = builder.Build(); app.UseAuthentication(); app.UseAuthorization(); app.MapControllers(); app.Run();appsettings.json 경고
클라이언트 비밀은 보안 위험으로 인해 에이전트 ID 청사진에 대한 프로덕션 환경에서 클라이언트 자격 증명으로 사용해서는 안 됩니다. 대신 관리 ID 또는 클라이언트 인증서와 함께 FIC(페더레이션 ID 자격 증명)와 같은 보다 안전한 인증 방법을 사용합니다. 이러한 메서드는 애플리케이션 구성 내에서 직접 중요한 비밀을 저장할 필요가 없도록 하여 향상된 보안을 제공합니다.
{ "AzureAd": { "Instance": "https://login.microsoftonline.com/", "TenantId": "<your-tenant>", "ClientId": "<agent-blueprint-id>", // Other client creedentials available. See <https://aka.ms/ms-id-web/client-credentials> "ClientCredentials": [ { "SourceType": "ClientSecret", "ClientSecret": "your-client-secret" } ] } }서비스 공급자로부터 토큰 자격 증명을 획득하고 Azure SDK 클라이언트와 함께 사용합니다.
에이전트 ID의 경우 이 메서드를 사용하여
WithAgentIdentity앱 전용 토큰(자율 에이전트) 또는 사용자 토큰(대화형 에이전트)을 대신해서 획득할 수 있습니다. 앱 전용 토큰의 경우 속성을RequestAppToken.로 설정합니다true. 사용자 토큰에 대해 대리로 위임된 경우, 속성을RequestAppToken또는 명시적으로false로 설정하지 마세요.using Microsoft.Identity.Web; public class AgentService { private readonly MicrosoftIdentityTokenCredential _credential; public AgentService(MicrosoftIdentityTokenCredential credential) { _credential = credential; } // Call Azure service with the agent identity for app only scenario public async Task<List<string>> ListBlobsForAgentAsync(string agentIdentity) { // Configure for agent identity string agentIdentity = "agent-identity-guid"; _credential.Options.WithAgentIdentity(agentIdentity); _credential.Options.RequestAppToken = true; 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; } // Call Azure service with the agent identity for on-behalf of user scenario public async Task<List<string>> ListBlobsForAgentAsync(string agentIdentity) { // Configure for agent identity var blobClient = new BlobServiceClient( new Uri("https://myaccount.blob.core.windows.net")); var container = blobClient.GetBlobContainerClient("agent-data"); var blobs = new List<string>(); await foreach (var blob in container.GetBlobsAsync()) { blobs.Add(blob.Name); } return blobs; } }에이전트의 사용자 계정에 대한 토큰을 획득할 수도 있습니다. 이렇게 하려면 UPN(사용자 계정 이름) 또는 OID(개체 ID)를 사용하여 에이전트의 사용자 계정을 식별할 수 있습니다.
개체 ID의 경우:
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>> ListBlobsForAgentAsync(string agentIdentity) { // Configure for agent identity string agentIdentity = "agent-identity-guid"; 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>> ListBlobsForAgentAsync(string agentIdentity) { // Configure for agent identity string agentIdentity = "agent-identity-guid"; string userUpn = "user@contoso.com"; _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; } }
관련 콘텐츠
- 사용자 지정 API 호출
Microsoft Graph