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.)
- var app = PublicClientApplicationBuilder.Create(clientId).WithRedirectUri("http://localhost").Build();Answer
- var result = await app.AcquireTokenInteractive(scopes).ExecuteAsync();Answer
- Cvar app = ConfidentialClientApplicationBuilder.Create(clientId).WithClientSecret(clientSecret).Build();
- Dvar app = ManagedIdentityApplicationBuilder.Create(ManagedIdentityId.SystemAssigned).Build();
Answer
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.
Step-by-Step Solution
Key Concept
Microsoft Identity Platform authentication for public client applications using MSAL.NET