Soru

Zorluk: OrtaMicrosoft Identity Platform Authentication

You are developing a C# desktop application that will run on local client workstations. The application must authenticate users using the Microsoft Identity Platform and call a secured downstream Web API. You need to write the MSAL.NET code to initialize the application and acquire the access token. Which two code segments should you use? (Select two.)

  1. var app = PublicClientApplicationBuilder.Create(clientId).WithRedirectUri("http://localhost").Build();Cevap
  2. var result = await app.AcquireTokenInteractive(scopes).ExecuteAsync();Cevap
  3. C
    var app = ConfidentialClientApplicationBuilder.Create(clientId).WithClientSecret(clientSecret).Build();
  4. D
    var app = ManagedIdentityApplicationBuilder.Create(ManagedIdentityId.SystemAssigned).Build();

Cevap

To initialize the application and acquire the token, you must build a public client application using PublicClientApplicationBuilder and acquire the token interactively using AcquireTokenInteractive.
For desktop applications running on local user machines, the application is classified as a public client because it cannot securely store secrets. Therefore, it must be initialized using PublicClientApplicationBuilder. To authenticate the user and obtain an access token, the application should initiate an interactive flow using AcquireTokenInteractive, which prompts the user for credentials.

Adım Adım Çözüm

1
Determine the application type and build the client application.
Initialize a public client application using PublicClientApplicationBuilder because desktop apps running on local machines cannot securely protect secrets.
Public client applications do not use client secrets or certificates for authentication since they run on untrusted client devices.
2
Select the appropriate MSAL.NET token acquisition method.
Call AcquireTokenInteractive to prompt the user for credentials and acquire the token.
Interactive authentication is the standard method for acquiring user-delegated tokens in public client desktop applications.

Anahtar Kavram

Microsoft Identity Platform authentication for public client applications using MSAL.NET
Bu soruyu puanla