Class CommunicationTokenCredential
- java.lang.Object
-
- com.azure.android.communication.common.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 Summary
Constructors Constructor Description CommunicationTokenCredential(CommunicationTokenRefreshOptions tokenRefreshOptions)
Creates aCommunicationTokenCredential
that automatically refreshes the token with a providedCallable
on a background thread.CommunicationTokenCredential(java.lang.String userToken)
Creates aCommunicationTokenCredential
from the provided token string.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
dispose()
Invalidates theCommunicationTokenCredential
instance 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 aCommunicationTokenCredential
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 aCommunicationTokenCredential
that automatically refreshes the token with a providedCallable
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
istrue
:- 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 credentialThis method returns an asynchronous
CompletableFuture
with the AccessToken. When theCommunicationTokenCredential
is constructed with atokenRefresher
Callable
, the AccessToken will automatically be updated as part of theCompletableFuture
if the cached token exceeds the expiry threshold.If this method is called after
dispose()
has been invoked, a failedCompletableFuture
that emitsIllegalStateException
will be returned.- Returns:
- Asynchronous
CompletableFuture
with the AccessToken
-
dispose
public void dispose()
Invalidates theCommunicationTokenCredential
instance to free up resources for garbage collection.
-
-