Class DeviceCodeCredential
A Azure.Core.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.
public class DeviceCodeCredential : TokenCredential
- Inheritance
-
DeviceCodeCredential
Constructors
DeviceCodeCredential()
Creates a new DeviceCodeCredential, which will authenticate users using the device code flow.
public DeviceCodeCredential()
DeviceCodeCredential(DeviceCodeCredentialOptions)
Creates a new DeviceCodeCredential with the specified options, which will authenticate users using the device code flow.
public DeviceCodeCredential(DeviceCodeCredentialOptions options)
Parameters
options
DeviceCodeCredentialOptionsThe client options for the newly created DeviceCodeCredential.
Methods
Authenticate(TokenRequestContext, CancellationToken)
Interactively authenticates a user via the default browser.
public virtual AuthenticationRecord Authenticate(TokenRequestContext requestContext, CancellationToken cancellationToken = default)
Parameters
requestContext
TokenRequestContextThe details of the authentication request.
cancellationToken
CancellationTokenA CancellationToken controlling the request lifetime.
Returns
- AuthenticationRecord
The AuthenticationRecord of the authenticated account.
Authenticate(CancellationToken)
Interactively authenticates a user via the default browser.
public virtual AuthenticationRecord Authenticate(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenA CancellationToken controlling the request lifetime.
Returns
- AuthenticationRecord
The result of the authentication request, containing the acquired Azure.Core.AccessToken, and the AuthenticationRecord which can be used to silently authenticate the account.
AuthenticateAsync(TokenRequestContext, CancellationToken)
Interactively authenticates a user via the default browser.
public virtual Task<AuthenticationRecord> AuthenticateAsync(TokenRequestContext requestContext, CancellationToken cancellationToken = default)
Parameters
requestContext
TokenRequestContextThe details of the authentication request.
cancellationToken
CancellationTokenA CancellationToken controlling the request lifetime.
Returns
- Task<AuthenticationRecord>
The AuthenticationRecord of the authenticated account.
AuthenticateAsync(CancellationToken)
Interactively authenticates a user via the default browser.
public virtual Task<AuthenticationRecord> AuthenticateAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenA CancellationToken controlling the request lifetime.
Returns
- Task<AuthenticationRecord>
The AuthenticationRecord which can be used to silently authenticate the account on future execution of credentials using the same persisted token cache.
GetToken(TokenRequestContext, CancellationToken)
Obtains a token for a user account, authenticating them through the device code authentication flow. Acquired tokens are cached by the credential instance. Token lifetime and refreshing is handled automatically. Where possible, reuse credential instances to optimize cache effectiveness.
public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken = default)
Parameters
requestContext
TokenRequestContextThe details of the authentication request.
cancellationToken
CancellationTokenA CancellationToken controlling the request lifetime.
Returns
- AccessToken
An Azure.Core.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. Acquired tokens are cached by the credential instance. Token lifetime and refreshing is handled automatically. Where possible, reuse credential instances to optimize cache effectiveness.
public override ValueTask<AccessToken> GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken = default)
Parameters
requestContext
TokenRequestContextThe details of the authentication request.
cancellationToken
CancellationTokenA CancellationToken controlling the request lifetime.
Returns
- ValueTask<AccessToken>
An Azure.Core.AccessToken which can be used to authenticate service client calls.