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 |
---|
CommunicationTokenCredential(CommunicationTokenRefreshOptions tokenRefreshOptions)
Creates a
CommunicationTokenCredential that automatically refreshes the token
with a provided Callable on a background thread. |
CommunicationTokenCredential(java.lang.String userToken)
Creates a
CommunicationTokenCredential from the provided token string. |
Modifier and Type | Method and Description |
---|---|
void |
dispose()
Invalidates the
CommunicationTokenCredential instance to free up resources for garbage collection. |
java9.util.concurrent.CompletableFuture<CommunicationAccessToken> |
getToken()
Get Azure core access token from credential
|
public CommunicationTokenCredential(java.lang.String userToken)
CommunicationTokenCredential
from the provided token string.
The same token will be returned whenever getToken()
is called.
userToken
- token string for initializationpublic CommunicationTokenCredential(CommunicationTokenRefreshOptions tokenRefreshOptions)
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
:
initialToken
is expiredtokenRefreshOptions
- Options object that contains token refresher, initial token string,
and refreshProactivelypublic java9.util.concurrent.CompletableFuture<CommunicationAccessToken> getToken()
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.
CompletableFuture
with the AccessTokenpublic void dispose()
CommunicationTokenCredential
instance to free up resources for garbage collection.