Azure / azure-iot-sdk-csharp

A C# SDK for connecting devices to Microsoft Azure IoT services
Other
464 stars 493 forks source link

Device not able to connect module twin #3333

Closed jsquire closed 1 year ago

jsquire commented 1 year ago

Issue Transfer

This issue has been transferred from the Azure SDK for .NET repository, #36356.

Please be aware that @ravi-mungalpara is the author of the original issue and include them for any questions or replies.

Details

Library name and version

Microsoft.Azure.Devices.Client: 1.41.0

Describe the bug

Hi,

My device is registered in IoTHub with x.509 certificate. I am trying to connect IoTHub over MQTT via console app but it gives UnauthorizedException. Same code is working for AMQP protocol. Not sure what could be the issue. Here is the sample code.


string ModuleModelId = "dtmi:azure:iot:deviceUpdateModel;2";

        var modelOptions = new ClientOptions { ModelId = ModuleModelId };
        ModuleClient moduleClient = ModuleClient.CreateFromConnectionString($"{parameters.IoTHubConnectionString};DeviceId={deviceId};ModuleId={moduleId}",
            TransportType.Mqtt, modelOptions);

Expected behavior

Device should be able to fetch device/module twin.

Actual behavior

Device is getting unauthorized access.

Reproduction Steps

Environment

Facing issues on dev environment.

ravi-mungalpara commented 1 year ago

Hi team,

Just wanted to check if there is any update here ?

tmahmood-microsoft commented 1 year ago

Hi @jsquire can you provide details about what fields are you providing in the parameters.IoTHubConnectionString and also, how are you providing certificate information, since the device you are connecting to is registered with x509 certificate.

jsquire commented 1 year ago

Hi @jsquire can you provide details about what fields are you providing in the parameters.IoTHubConnectionString and also, how are you providing certificate information, since the device you are connecting to is registered with x509 certificate.

You'll want to ask @ravi-mungalpara who is the author of the original issue.

sourabhkrishna commented 1 year ago

@tmahmood-microsoft Will we be able to spin up the device client using the iothubowner shared access policy for a device that is registered with an x509?

tmahmood-microsoft commented 1 year ago

Hi @sourabhkrishna we are still looking into this. I have raised this issue with the relevant team. I will keep you posted on any updates. Let me know if you have any further issues. Thanks.

tmahmood-microsoft commented 1 year ago

Hi @ravi-mungalpara, @sourabhkrishna, sorry for the delay on this. It looks like this indeed is a bug in IoT Hub v1 and we currently have IoT Hub v2 which already has a fix for this specific issue. I would need your permission and name(s) of IoT hub(s) you want us to migrate to v2.

sourabhkrishna commented 1 year ago

Can you share more about IoTHub V2 and what are the new features compared to v1 ?

tmahmood-microsoft commented 1 year ago

IoT Hub V2 is designed to be in full parity with V1, it does not contain many new features, mostly fix for bugs in V1. From a user's point of view, you should not observe any differences in functionality or usage with IoT Hub V2.

sourabhkrishna commented 1 year ago

So is this an internal thing at some point in time that MS will force migrate all v1 hubs to v2?

tmahmood-microsoft commented 1 year ago

Yes, v2 IoT Hubs are internal and Microsoft is currently in process of migrating all v1 hubs to v2.

tmahmood-microsoft commented 1 year ago

Hi @sourabhkrishna I am closing this issue due to inactivity, if you still need assistance, feel free to re-open this.