Soru

Zorluk: OrtaMicrosoft Identity Platform Authentication

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.)

  1. In the `Program.cs` file, call `builder.Services.AddMicrosoftIdentityWebApi(builder.Configuration);` to register token validation services.Cevap
  2. In the `appsettings.json` file, create an `AzureAd` configuration section containing the `Instance`, `Domain`, `TenantId`, and `ClientId` keys.Cevap
  3. C
    In the `Program.cs` file, call `builder.Services.AddMicrosoftIdentityWebApp(builder.Configuration);` to register web app authentication services.
  4. D
    In 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

1
Configure the ASP.NET Core application's Program.cs to use Microsoft.Identity.Web services.
The authentication services are registered using the `AddMicrosoftIdentityWebApi` method.
This method configures the Web API to validate incoming JWT bearer tokens.
2
Add the connection parameters to the configuration file.
The application configuration has an `AzureAd` section with `Instance`, `Domain`, `TenantId`, and `ClientId` keys.
The library relies on these settings to obtain metadata and locate the authority for token validation.

Anahtar Kavram

Configuring token validation in an ASP.NET Core Web API using Microsoft.Identity.Web.
Bu soruyu puanla