TokenCredentialCache Class

  • java.lang.Object
    • com.microsoft.azure.sdk.iot.service.auth.TokenCredentialCache

public class TokenCredentialCache

This class generates AAD authentication tokens from a TokenCredential but caches previous tokens when they aren't near expiry.

Field Summary

Modifier and Type Field and Description
static final java.lang.String BEARER_TOKEN_PREFIX
static final java.lang.String[] IOTHUB_PUBLIC_SCOPE

Constructor Summary

Constructor Description
TokenCredentialCache(TokenCredential tokenCredential)

Construct a new TokenCredentialCache instance.

Method Summary

Modifier and Type Method and Description
AccessToken getAccessToken()

Get a valid AAD authentication token.

TokenCredential getTokenCredential()
java.lang.String getTokenString()

Get the access token string, including the Bearer prefix.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Field Details

BEARER_TOKEN_PREFIX

public static final String BEARER_TOKEN_PREFIX

IOTHUB_PUBLIC_SCOPE

public static final String[] IOTHUB_PUBLIC_SCOPE

Constructor Details

TokenCredentialCache

public TokenCredentialCache(TokenCredential tokenCredential)

Construct a new TokenCredentialCache instance.

Parameters:

tokenCredential - The tokenCredential instance that this cache will use to generate new tokens.

Method Details

getAccessToken

public AccessToken getAccessToken()

Get a valid AAD authentication token. This may be the same as a previously returned token if it is not near expiration time yet. If a token is less than or equal to 9 minutes away from expiring or is expired already, the token will be renewed. Otherwise, a cached token will be returned.

Returns:

a valid AAD authentication token.

getTokenCredential

public TokenCredential getTokenCredential()

Returns:

the TokenCredential instance that was set in the constructor.

getTokenString

public String getTokenString()

Get the access token string, including the Bearer prefix.

Returns:

the access token string, including the Bearer prefix.

Applies to