IPublicClientApplication.AcquireTokenWithDeviceCode Method

Definition

Acquires a token on a device without a web browser by letting the user authenticate on another device. This method does not look in the token cache, but stores the result in it. Before calling this method, use other methods such as AcquireTokenSilent(IEnumerable<String>, IAccount) to check the token cache.

public Microsoft.Identity.Client.AcquireTokenWithDeviceCodeParameterBuilder AcquireTokenWithDeviceCode (System.Collections.Generic.IEnumerable<string> scopes, Func<Microsoft.Identity.Client.DeviceCodeResult,System.Threading.Tasks.Task> deviceCodeResultCallback);
abstract member AcquireTokenWithDeviceCode : seq<string> * Func<Microsoft.Identity.Client.DeviceCodeResult, System.Threading.Tasks.Task> -> Microsoft.Identity.Client.AcquireTokenWithDeviceCodeParameterBuilder
Public Function AcquireTokenWithDeviceCode (scopes As IEnumerable(Of String), deviceCodeResultCallback As Func(Of DeviceCodeResult, Task)) As AcquireTokenWithDeviceCodeParameterBuilder

Parameters

scopes
IEnumerable<String>

Scopes requested to access a protected API.

deviceCodeResultCallback
Func<DeviceCodeResult,Task>

Callback containing information to show the user about how to authenticate and enter the device code.

Returns

A builder enabling you to add optional parameters before executing the token request.

Remarks

The token acquisition is done in two steps:

  • The method first acquires a device code from the authority and returns it to the caller via the deviceCodeResultCallback. This callback takes care of interacting with the user to direct them to authenticate (i.e., to a specific URL, with a code).
  • The method then proceeds to poll for the security token which is granted upon successful login by the user based on the device code information.
See Device Code Flow.

Applies to