IotHubSasTokenAuthenticationProvider Class

public abstract class IotHubSasTokenAuthenticationProvider
extends IotHubAuthenticationProvider

Field Summary

Modifier and Type Field and Description
protected static final java.lang.String ENCODING_FORMAT_NAME
protected static final long MILLISECONDS_PER_SECOND
protected static final long MINIMUM_EXPIRATION_TIME_OFFSET
protected IotHubSasToken sasToken
protected int timeBufferPercentage

The percentage of a sas token's life that will happen before it should be renewed.

protected long tokenValidSecs

The number of seconds after which the generated SAS token for a message will become invalid.

Constructor Summary

Constructor Description
IotHubSasTokenAuthenticationProvider(String hostname, String gatewayHostname, String deviceId, String moduleId)
IotHubSasTokenAuthenticationProvider(String hostname, String gatewayHostname, String deviceId, String moduleId, SSLContext sslContext)
IotHubSasTokenAuthenticationProvider(String hostname, String gatewayHostname, String deviceId, String moduleId, long tokenValidSecs, int timeBufferPercentage)

Method Summary

Modifier and Type Method and Description
abstract boolean canRefreshToken()
int getMillisecondsBeforeProactiveRenewal()
abstract char[] getSasToken()
long getTokenValidSecs()
boolean isAuthenticationProviderRenewalNecessary()

Returns true if the this authentication provider is no longer valid.

void setTokenValidSecs(long tokenValidSecs)
boolean shouldRefreshToken(boolean proactivelyRenew)

Returns true if the saved token should be refreshed

Methods inherited from IotHubAuthenticationProvider

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

ENCODING_FORMAT_NAME

protected static final String ENCODING_FORMAT_NAME

MILLISECONDS_PER_SECOND

protected static final long MILLISECONDS_PER_SECOND

MINIMUM_EXPIRATION_TIME_OFFSET

protected static final long MINIMUM_EXPIRATION_TIME_OFFSET

sasToken

protected IotHubSasToken sasToken

timeBufferPercentage

protected int timeBufferPercentage

The percentage of a sas token's life that will happen before it should be renewed. Between 1 and 100

tokenValidSecs

protected long tokenValidSecs

The number of seconds after which the generated SAS token for a message will become invalid. We also use the expiry time, which is computed as currentTime() + DEVICE_KEY_VALID_LENGTH, as a salt when generating our SAS token.

Constructor Details

IotHubSasTokenAuthenticationProvider

public IotHubSasTokenAuthenticationProvider(String hostname, String gatewayHostname, String deviceId, String moduleId)

Parameters:

hostname
gatewayHostname
deviceId
moduleId

IotHubSasTokenAuthenticationProvider

public IotHubSasTokenAuthenticationProvider(String hostname, String gatewayHostname, String deviceId, String moduleId, SSLContext sslContext)

Parameters:

hostname
gatewayHostname
deviceId
moduleId
sslContext

IotHubSasTokenAuthenticationProvider

public IotHubSasTokenAuthenticationProvider(String hostname, String gatewayHostname, String deviceId, String moduleId, long tokenValidSecs, int timeBufferPercentage)

Parameters:

hostname
gatewayHostname
deviceId
moduleId
tokenValidSecs
timeBufferPercentage

Method Details

canRefreshToken

public abstract boolean canRefreshToken()

getMillisecondsBeforeProactiveRenewal

public int getMillisecondsBeforeProactiveRenewal()

getSasToken

public abstract char[] getSasToken()

Throws:

java.io.IOException

getTokenValidSecs

public long getTokenValidSecs()

isAuthenticationProviderRenewalNecessary

public boolean isAuthenticationProviderRenewalNecessary()

Returns true if the this authentication provider is no longer valid. If true, users will need to create a new DeviceClient instance to get a new authentication provider. The most common case for this is if the user provides a SAS token, but no symmetric key, and that SAS token has expired. At that point, the user's client won't be able to authenticate anymore.

Returns:

true if the this authentication provider is no longer valid. False otherwise

setTokenValidSecs

public void setTokenValidSecs(long tokenValidSecs)

Parameters:

tokenValidSecs

shouldRefreshToken

public boolean shouldRefreshToken(boolean proactivelyRenew)

Returns true if the saved token should be refreshed

Parameters:

proactivelyRenew - if true, this function will return true even if the saved token has not expired, but only if the token has lived beyond its time buffer percentage

Returns:

true if the caller should refresh the saved sas token

Applies to