Class DeviceCodeCredential
A TokenCredential implementation which authenticates a user using the device code flow, and provides access tokens for that user account. For more information on the device code authentication flow see https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/Device-Code-Flow.
Namespace: Azure.Identity
Assembly: Azure.Identity.dll
Syntax
public class DeviceCodeCredential : Azure.Core.TokenCredential
Constructors
DeviceCodeCredential()
Protected constructor for mocking
Declaration
protected DeviceCodeCredential ();
DeviceCodeCredential(Func<DeviceCodeInfo,CancellationToken,Task>, String, TokenCredentialOptions)
Creates a new DeviceCodeCredential with the specifeid options, which will authenticate users with the specified application.
Declaration
public DeviceCodeCredential (Func<Azure.Identity.DeviceCodeInfo,System.Threading.CancellationToken,System.Threading.Tasks.Task> deviceCodeCallback, string clientId, Azure.Identity.TokenCredentialOptions options = null);
Parameters
Func<DeviceCodeInfo,CancellationToken,Task>
deviceCodeCallback
The callback to be executed to display the device code to the user |
String
clientId
The client id of the application to which the users will authenticate |
TokenCredentialOptions
options
The client options for the newly created DeviceCodeCredential |
DeviceCodeCredential(Func<DeviceCodeInfo,CancellationToken,Task>, String, String, TokenCredentialOptions)
Creates a new DeviceCodeCredential with the specifeid options, which will authenticate users with the specified application.
Declaration
public DeviceCodeCredential (Func<Azure.Identity.DeviceCodeInfo,System.Threading.CancellationToken,System.Threading.Tasks.Task> deviceCodeCallback, string tenantId, string clientId, Azure.Identity.TokenCredentialOptions options = null);
Parameters
Func<DeviceCodeInfo,CancellationToken,Task>
deviceCodeCallback
The callback to be executed to display the device code to the user |
String
tenantId
The tenant id of the application to which users will authenticate. This can be null for multi-tenanted applications. |
String
clientId
The client id of the application to which the users will authenticate |
TokenCredentialOptions
options
The client options for the newly created DeviceCodeCredential |
Methods
GetToken(TokenRequestContext, CancellationToken)
Obtains a token for a user account, authenticating them through the device code authentication flow. This method is called by Azure SDK clients. It isn't intended for use in application code.
Declaration
public override Azure.Core.AccessToken GetToken (Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken = null);
Parameters
Azure.Core.TokenRequestContext
requestContext
The details of the authentication request. |
CancellationToken
cancellationToken
A CancellationToken controlling the request lifetime. |
Returns
AccessToken
An AccessToken which can be used to authenticate service client calls. |
GetTokenAsync(TokenRequestContext, CancellationToken)
Obtains a token for a user account, authenticating them through the device code authentication flow. This method is called by Azure SDK clients. It isn't intended for use in application code.
Declaration
[System.Diagnostics.DebuggerStepThrough]
public override System.Threading.Tasks.ValueTask<Azure.Core.AccessToken> GetTokenAsync (Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken = null);
Parameters
Azure.Core.TokenRequestContext
requestContext
The details of the authentication request. |
CancellationToken
cancellationToken
A CancellationToken controlling the request lifetime. |
Returns
ValueTask<AccessToken>
An AccessToken which can be used to authenticate service client calls. |