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
final 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. 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.

TokenCredential getTokenCredential()
String getTokenString()

Get the access token string, including the Bearer prefix.

Field Details

IOTHUB_PUBLIC_SCOPE

public static final String [] IOTHUB_PUBLIC_SCOPE= new String[]{"https://iothubs.azure.net/.default"}

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