You are developing a backend service in C# using MSAL.NET that runs on an Azure App Service. The App Service has a user-assigned managed identity configured with the Client ID `d29d3368-8f83-4a25-97a1-872f23cf9e3c`. The service must securely access an Azure Key Vault without storing any secrets or certificates in the application configuration. Which two configuration steps should you implement in the C# code? (Select two.)
- Initialize the managed identity application by calling `ManagedIdentityApplicationBuilder.Create(ManagedIdentityId.WithUserAssignedClientId("d29d3368-8f83-4a25-97a1-872f23cf9e3c")).Build()`Answer
- Acquire the token by calling `app.AcquireTokenForManagedIdentity("https://vault.azure.net/.default").ExecuteAsync()` on the initialized application instanceAnswer
- CInitialize the managed identity application by calling `ManagedIdentityApplicationBuilder.Create(ManagedIdentityId.SystemAssigned).Build()`
- DAcquire the token by calling `app.AcquireTokenForClient(new[] { "https://vault.azure.net/.default" }).ExecuteAsync()` on the application instance
- EInitialize the managed identity application by calling `ManagedIdentityApplicationBuilder.Create(ManagedIdentityId.WithUserAssignedResourceId("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myId")).Build()`
Answer
Initialize the managed identity application by calling ManagedIdentityApplicationBuilder.Create(ManagedIdentityId.WithUserAssignedClientId("d29d3368-8f83-4a25-97a1-872f23cf9e3c")).Build(), and acquire the token by calling app.AcquireTokenForManagedIdentity("https://vault.azure.net/.default").ExecuteAsync() on the initialized application instance.
To authenticate using a user-assigned managed identity via MSAL.NET, you must initialize the application using ManagedIdentityApplicationBuilder with ManagedIdentityId.WithUserAssignedClientId to specify the client ID. Once configured, you must call AcquireTokenForManagedIdentity on the application instance to acquire a token for the Azure Key Vault resource scope.
Step-by-Step Solution
Key Concept
Configuring MSAL.NET to acquire tokens using a user-assigned managed identity with its Client ID.