IotHubSasTokenWithRefreshAuthenticationProvider Class

public abstract class IotHubSasTokenWithRefreshAuthenticationProvider
extends IotHubSasTokenAuthenticationProvider

Authentication method that uses a shared access signature token and allows for token refresh.

Constructor Summary

Modifier Constructor Description
protected IotHubSasTokenWithRefreshAuthenticationProvider(String hostname, String gatewayHostName, String deviceId, String moduleId, String sharedAccessToken, int suggestedTimeToLiveSeconds, int timeBufferPercentage)

Constructor for IotHubSasTokenWithRefreshAuthenticationProvider

Method Summary

Modifier and Type Method and Description
protected static java.lang.String buildAudience(String hostname, String deviceId, String moduleId)

Constructs the audience string to be used in a sas token

char[] getSasToken()

Check if sas token should be renewed at all, and then renew it if necessary

boolean isAuthenticationProviderRenewalNecessary()

Returns false as instances of this class will always be able to renew their own sas token

abstract void refreshSasToken()

Renew the saved sas token

Methods inherited from IotHubAuthenticationProvider

Methods inherited from IotHubSasTokenAuthenticationProvider

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

Constructor Details

IotHubSasTokenWithRefreshAuthenticationProvider

protected IotHubSasTokenWithRefreshAuthenticationProvider(String hostname, String gatewayHostName, String deviceId, String moduleId, String sharedAccessToken, int suggestedTimeToLiveSeconds, int timeBufferPercentage)

Constructor for IotHubSasTokenWithRefreshAuthenticationProvider

Parameters:

hostname - the hostname
gatewayHostName - the gateway hostname
deviceId - the device id
moduleId - the module id
sharedAccessToken - the shared access token
suggestedTimeToLiveSeconds - the time to live for generated tokens
timeBufferPercentage - the percent of a sas token's life to live before renewing

Method Details

buildAudience

protected static String buildAudience(String hostname, String deviceId, String moduleId)

Constructs the audience string to be used in a sas token

Parameters:

hostname - the hostname
deviceId - the device id
moduleId - the module id

Returns:

the audience

Throws:

java.io.UnsupportedEncodingException - if UTF-8 encoding is not supported

getSasToken

public char[] getSasToken()

Check if sas token should be renewed at all, and then renew it if necessary

Overrides:

IotHubSasTokenWithRefreshAuthenticationProvider.getSasToken()

Returns:

the renewed token, or the old token if it did not need to be renewed

Throws:

java.io.IOException - If an IOException is encountered while refreshing the sas token
TransportException - If an IOException is encountered while refreshing the sas token

isAuthenticationProviderRenewalNecessary

public boolean isAuthenticationProviderRenewalNecessary()

Returns false as instances of this class will always be able to renew their own sas token

Overrides:

IotHubSasTokenWithRefreshAuthenticationProvider.isAuthenticationProviderRenewalNecessary()

Returns:

false

refreshSasToken

public abstract void refreshSasToken()

Renew the saved sas token

Throws:

java.io.IOException - If an IOException is encountered while refreshing the sas token
TransportException - If an IOException is encountered while refreshing the sas token

Applies to