0

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.

joppiesaus
  • 5,471
  • 3
  • 26
  • 36

2 Answers2

0

This issue only exists with MQTT for me. I test with Microsoft.Azure.Devices.Client 1.17.0.

As for AMQP and HTTP, the device connection is not severed by IoT Hub immediately, for AMQP, about 10 minutes after the token expires you will get UnauthorizedException. For HTTP, this time is about 5 minutes.

I have opened an issue about MQTT on Azure IoT Hub SDK for C# on GitHub.

Rita Han
  • 9,574
  • 1
  • 11
  • 24
  • Thank you. I didn't know that we should wait for 10 mins for the token to expire in AMQP. But why is it like that? – Poonkuzhali Jul 26 '18 at 06:36
  • @PoonkuzhaliVasudevan I am not sure about why is it like. You can monitor the [issue](https://github.com/Azure/azure-iot-sdk-csharp/issues/565) I opened. I'll update here if there is an update. – Rita Han Jul 26 '18 at 07:48
0

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