Class CommunicationTokenCredential


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

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

    • Constructor Detail

      • CommunicationTokenCredential

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

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

        Parameters:
        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
        Parameters:
        tokenRefreshOptions - Options object that contains token refresher, initial token string, and refreshProactively
    • Method Detail

      • 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.

        Returns:
        Asynchronous CompletableFuture with the AccessToken