Search code examples
c#azureazure-iot-hubazure-iot-hub-device-management

Azure IoTHub- SAS token does not expire


Package version: Microsoft.Azure.Devices.Client 1.17.0

I have created a device client in the following way

deviceClient = DeviceClient.Create(s_iotHubUri, new DeviceAuthenticationWithToken(deviceId, sasToken), Microsoft.Azure.Devices.Client.TransportType.Amqp);

I use the deviceClient to send messages using deviceClient.SendEventAsync(message). The SAS expiry is set to be 5 mins (for example) but the SAS is not expiring at all and the messages are being sent using the device client. I expect an exception like:

SAS has expired

But messages are being sent normally. But if I stop the connection and try to create a client using the same SAS, I get SAS expired exception but why does this not happen while sending messages to device?

Please help with this issue.


Solution

  • According to the following git hub issues, https://github.com/Azure/azure-iot-sdk-csharp/issues/564 and https://github.com/Azure/azure-iot-sdk-csharp/issues/565. With the new c# SDK version,

    Microsoft.Azure.Devices.Client 1.17.1

    IoTHub stops accepting token for MQTT in 10 min after SAS expiry time set by user, which is consistent with AMQP behaviour. The delay is by design and used to cover up for clock difference(timing skew).