Class DeviceCodeCredential

java.lang.Object
com.azure.identity.DeviceCodeCredential
All Implemented Interfaces:
TokenCredential

public class DeviceCodeCredential extends Object implements TokenCredential
An AAD credential that acquires a token with a device code for an AAD application.
  • Method Details

    • getToken

      public Mono<AccessToken> getToken(TokenRequestContext request)
      Description copied from interface: TokenCredential
      Asynchronously get a token for a given resource/audience. This method is called automatically by Azure SDK client libraries. You may call this method directly, but you must also handle token caching and token refreshing.
      Specified by:
      getToken in interface TokenCredential
      Parameters:
      request - the details of the token request
      Returns:
      a Publisher that emits a single access token
    • authenticate

      public Mono<AuthenticationRecord> authenticate(TokenRequestContext request)
      Authenticates a user via the device code flow.

      The credential acquires a verification URL and code from the Azure Active Directory. The user must browse to the URL, enter the code, and authenticate with Azure Active Directory. If the user authenticates successfully, the credential receives an access token.

      Parameters:
      request - The details of the authentication request.
      Returns:
      The AuthenticationRecord which can be used to silently authenticate the account on future execution if persistent caching was configured via DeviceCodeCredentialBuilder.tokenCachePersistenceOptions(TokenCachePersistenceOptions) when credential was instantiated.
    • authenticate

      public Mono<AuthenticationRecord> authenticate()
      Authenticates a user via the device code flow.

      The credential acquires a verification URL and code from the Azure Active Directory. The user must browse to the URL, enter the code, and authenticate with Azure Active Directory. If the user authenticates successfully, the credential receives an access token.

      Returns:
      The AuthenticationRecord which can be used to silently authenticate the account on future execution if persistent caching was configured via DeviceCodeCredentialBuilder.tokenCachePersistenceOptions(TokenCachePersistenceOptions) when credential was instantiated.