You are developing a C# background worker service that runs on an on-premises server. The service must periodically query a secured downstream web API without any user interaction. You register the service in Microsoft Entra ID as a daemon application. You need to write code using MSAL.NET to acquire an access token for the downstream API.
Which two code segments should you use to instantiate the application client and acquire the token? (Select two.)
- var app = ConfidentialClientApplicationBuilder.Create(clientId).WithClientSecret(clientSecret).WithAuthority(authority).Build();Cevap
- Bvar app = PublicClientApplicationBuilder.Create(clientId).WithAuthority(authority).Build();
- var result = await app.AcquireTokenForClient(scopes).ExecuteAsync();Cevap
- Dvar result = await app.AcquireTokenInteractive(scopes).ExecuteAsync();
Cevap
To instantiate the application client and acquire the token for a daemon application, you must use ConfidentialClientApplicationBuilder to create the client and call AcquireTokenForClient to retrieve the token.
For daemon applications running without user interaction, MSAL.NET requires a confidential client application configuration. The correct setup uses ConfidentialClientApplicationBuilder to define the client with a client secret and AcquireTokenForClient to perform the OAuth 2.0 Client Credentials grant flow.
Adım Adım Çözüm
Anahtar Kavram
Authenticating daemon applications with MSAL.NET using the Client Credentials flow