Class AuthorizationCodeCredential

java.lang.Object
com.azure.identity.AuthorizationCodeCredential
All Implemented Interfaces:
com.azure.core.credential.TokenCredential

public class AuthorizationCodeCredential extends Object implements com.azure.core.credential.TokenCredential

Authorization Code authentication in Azure is a type of authentication mechanism that allows users to authenticate with Microsoft Entra ID and obtain an authorization code that can be used to request an access token to access Azure resources. It is a widely used authentication mechanism and is supported by a wide range of Azure services and applications. It provides a secure and scalable way to authenticate users and grant them access to Azure resources. The AuthorizationCodeCredential authenticates a user or an application and acquires a token with the configured authorization code and the redirectURL where authorization code was received.

Sample: Construct AuthorizationCodeCredential

The following code sample demonstrates the creation of a AuthorizationCodeCredential, using the AuthorizationCodeCredentialBuilder to configure it. The authorizationCode, redirectUrl and clientId are required to be configured to create AuthorizationCodeCredential. Once this credential is created, it may be passed into the builder of many of the Azure SDK for Java client builders as the 'credential' parameter.

 TokenCredential authorizationCodeCredential = new AuthorizationCodeCredentialBuilder()
     .authorizationCode("{authorization-code-received-at-redirectURL}")
     .redirectUrl("{redirectUrl-where-authorization-code-is-received}")
     .clientId("{clientId-of-application-being-authenticated")
     .build();
 
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Mono<com.azure.core.credential.AccessToken>
    getToken(com.azure.core.credential.TokenRequestContext request)
    Asynchronously get a token for a given resource/audience.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.azure.core.credential.TokenCredential

    getTokenSync
  • Method Details

    • getToken

      public Mono<com.azure.core.credential.AccessToken> getToken(com.azure.core.credential.TokenRequestContext request)
      Description copied from interface: com.azure.core.credential.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 com.azure.core.credential.TokenCredential
      Parameters:
      request - the details of the token request
      Returns:
      a Publisher that emits a single access token