Class CommunicationTokenCredential


public final class CommunicationTokenCredential extends Object
The Azure Communication Services User token credential.

This class is used to cache/refresh the access token required by Azure Communication Services.

  • Constructor Details

    • CommunicationTokenCredential

      public CommunicationTokenCredential(String userToken)
      Creates a CommunicationTokenCredential from the provided token string.

      The same token will be returned whenever getToken() is called.

      userToken - token string for initialization
    • CommunicationTokenCredential

      public CommunicationTokenCredential(CommunicationTokenRefreshOptions tokenRefreshOptions)
      Creates a CommunicationTokenCredential that automatically refreshes the token with a provided Callable on a background thread.

      The cached token is updated if getToken() is called and if the difference between the current time and token expiry time is less than 120s.

      If refreshProactively is true:

      • The cached token will be updated in the background when the difference between the current time and token expiry time is less than 600s.
      • The cached token will be updated immediately when the constructor is invoked and initialToken is expired
      tokenRefreshOptions - Options object that contains token refresher, initial token string, and refreshProactively
  • Method Details

    • getToken

      public java9.util.concurrent.CompletableFuture<CommunicationAccessToken> getToken()
      Get Azure core access token from credential

      This method returns an asynchronous CompletableFuture with the AccessToken. When the CommunicationTokenCredential is constructed with a tokenRefresher Callable, the AccessToken will automatically be updated as part of the CompletableFuture if the cached token exceeds the expiry threshold.

      If this method is called after dispose() has been invoked, a failed CompletableFuture that emits IllegalStateException will be returned.

      Asynchronous CompletableFuture with the AccessToken
    • dispose

      public void dispose()
      Invalidates the CommunicationTokenCredential instance to free up resources for garbage collection.