You are developing an ASP.NET Core Web API that must secure its endpoints using the Microsoft Identity Platform. The Web API will accept JWT access tokens sent by client applications in the HTTP Authorization header. You need to configure the Web API to validate these tokens using the `Microsoft.Identity.Web` library. Which two actions should you perform to complete the configuration? (Select two.)
- In the `Program.cs` file, call `builder.Services.AddMicrosoftIdentityWebApi(builder.Configuration);` to register token validation services.Cevap
- In the `appsettings.json` file, create an `AzureAd` configuration section containing the `Instance`, `Domain`, `TenantId`, and `ClientId` keys.Cevap
- CIn the `Program.cs` file, call `builder.Services.AddMicrosoftIdentityWebApp(builder.Configuration);` to register web app authentication services.
- DIn the `appsettings.json` file, create a `ClientCredentials` section containing a `ClientSecret` and configure the API to fetch it from Azure Key Vault.
Cevap
To configure the Web API to validate tokens using Microsoft.Identity.Web, you must call builder.Services.AddMicrosoftIdentityWebApi(builder.Configuration) in Program.cs and define the AzureAd configuration section in appsettings.json.
To secure an ASP.NET Core Web API using the Microsoft Identity Platform, you use the `Microsoft.Identity.Web` library. First, you configure the authentication middleware in the `Program.cs` file by calling `AddMicrosoftIdentityWebApi(builder.Configuration)`. Second, you provide the registration details under the `AzureAd` section in the `appsettings.json` file so the middleware knows which tenant and client ID to validate the tokens against.
Adım Adım Çözüm
Anahtar Kavram
Configuring token validation in an ASP.NET Core Web API using Microsoft.Identity.Web.