public final class CommunicationTokenCredential extends java.lang.Object
This class is used to cache/refresh the access token required by Azure Communication Services.
|Constructor and Description|
|Modifier and Type||Method and Description|
Get Azure core access token from credential
public CommunicationTokenCredential(java.lang.String userToken)
CommunicationTokenCredentialfrom the provided token string.
The same token will be returned whenever
getToken() is called.
userToken- token string for initialization
public CommunicationTokenCredential(CommunicationTokenRefreshOptions tokenRefreshOptions)
CommunicationTokenCredentialthat automatically refreshes the token with a provided
Callableon 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.
tokenRefreshOptions- Options object that contains token refresher, initial token string, and refreshProactively
public java9.util.concurrent.CompletableFuture<CommunicationAccessToken> getToken()
This method returns an asynchronous
CompletableFuture with the AccessToken.
CommunicationTokenCredential is constructed with a
Callable, the AccessToken will automatically be updated as part of
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.
CompletableFuturewith the AccessToken
public void dispose()
CommunicationTokenCredentialinstance to free up resources for garbage collection.