Class CommunicationTokenCredential
- java.lang.Object
-
- com.azure.android.communication.common.CommunicationTokenCredential
-
public final class CommunicationTokenCredential extends java.lang.ObjectThe Azure Communication Services User token credential.This class is used to cache/refresh the access token required by Azure Communication Services.
-
-
Constructor Summary
Constructors Constructor Description CommunicationTokenCredential(CommunicationTokenRefreshOptions tokenRefreshOptions)Creates aCommunicationTokenCredentialthat automatically refreshes the token with a providedCallableon a background thread.CommunicationTokenCredential(java.lang.String userToken)Creates aCommunicationTokenCredentialfrom the provided token string.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddispose()Invalidates theCommunicationTokenCredentialinstance to free up resources for garbage collection.java9.util.concurrent.CompletableFuture<CommunicationAccessToken>getToken()Get Azure core access token from credential
-
-
-
Constructor Detail
-
CommunicationTokenCredential
public CommunicationTokenCredential(java.lang.String userToken)
Creates aCommunicationTokenCredentialfrom 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 aCommunicationTokenCredentialthat automatically refreshes the token with a providedCallableon 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
refreshProactivelyistrue:- 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
initialTokenis 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 credentialThis method returns an asynchronous
CompletableFuturewith the AccessToken. When theCommunicationTokenCredentialis constructed with atokenRefresherCallable, the AccessToken will automatically be updated as part of theCompletableFutureif the cached token exceeds the expiry threshold.If this method is called after
dispose()has been invoked, a failedCompletableFuturethat emitsIllegalStateExceptionwill be returned.- Returns:
- Asynchronous
CompletableFuturewith the AccessToken
-
dispose
public void dispose()
Invalidates theCommunicationTokenCredentialinstance to free up resources for garbage collection.
-
-