You are developing a C# command-line interface (CLI) tool that will be executed by system administrators on headless Linux servers. The tool must authenticate the administrators using their individual Microsoft Entra ID credentials to access a secure downstream Web API. The administrators' accounts have multi-factor authentication (MFA) enabled. Which MSAL.NET method should you use to acquire the token?
- IPublicClientApplication.AcquireTokenWithDeviceCodeAnswer
- BIPublicClientApplication.AcquireTokenInteractive
- CIPublicClientApplication.AcquireTokenByUsernamePassword
- DIConfidentialClientApplication.AcquireTokenForClient
Answer
IPublicClientApplication.AcquireTokenWithDeviceCode
The method utilizing the Device Code flow is correct because it allows user authentication on headless or input-constrained devices by prompting the user to complete the login process, including any required Multi-Factor Authentication (MFA), on a separate device with a web browser.
Step-by-Step Solution
Key Concept
Selecting the correct OAuth 2.0 authentication flow in MSAL.NET for input-constrained and headless environments.