Partilhar via


IotHubSasToken Class

  • java.lang.Object
    • com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken

public final class IotHubSasToken

Grants device access to an IoT Hub for the specified amount of time.

Constructor Summary

Modifier Constructor Description
protected IotHubSasToken()
IotHubSasToken(String hostname, String deviceId, String deviceKey, String sharedAccessToken, String moduleId, long expiryTime)

Constructor.

Method Summary

Modifier and Type Method and Description
static java.lang.String buildSharedAccessToken(String audience, String signature, long expiry)

Creates a shared access token from the provided audience, signature and expiry time

java.lang.String getSasToken()
static boolean isExpired(String sasToken)

Returns if the provided sasToken has expired yet or not

java.lang.String toString()

Returns the string representation of the SAS token.

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

IotHubSasToken

protected IotHubSasToken()

IotHubSasToken

public IotHubSasToken(String hostname, String deviceId, String deviceKey, String sharedAccessToken, String moduleId, long expiryTime)

Constructor. Generates a SAS token that grants access to an IoT Hub for the specified amount of time.

Parameters:

hostname - the hostname of the hub the token is for
deviceId - The id of the device the token is for
deviceKey - The device key for connecting the device to the hub with. May be null if sharedAccessToken is not.
sharedAccessToken - The sas token for connecting the device to the hub with. May be null if deviceKey is not.
moduleId - the module id. May be null if the sas token is not for a module
expiryTime - the time, as a UNIX timestamp, after which the token will become invalid

Method Details

buildSharedAccessToken

public static String buildSharedAccessToken(String audience, String signature, long expiry)

Creates a shared access token from the provided audience, signature and expiry time

Parameters:

audience - the audience of the token
signature - the signature of the token
expiry - when the token will expire, in seconds since the epoch

Returns:

the shared access token string

getSasToken

public String getSasToken()

isExpired

public static boolean isExpired(String sasToken)

Returns if the provided sasToken has expired yet or not

Parameters:

sasToken - the token to check for expiration

Returns:

a boolean true if the SasToken is still valid, or false if it is expired.

toString

public String toString()

Returns the string representation of the SAS token.

Overrides:

IotHubSasToken.toString()

Returns:

the string representation of the SAS token.

Applies to