Azure / Azure/azure-iot-sdk-csharp

[Bug Report] [IoTSDK] Issue with IotHubUnauthorizedAccess only when using X.509 Cert to GetFileUploadSasUriAsync[Bug Report]

Open
#3,364 0 comments 0 reactions 0 assignees View on GitHub
bug IoTSDK
Dominant language
C#
Stars
477
Forks
492
Avg merge
9h 55m
Merged PRs (30d)
2

Description

Hello
I implemented communication between a device and a IotHub.
I use Microsoft.Azure.devices.client 1.42.0 & Microsoft.Azure.devices.Provisioning.client 1.19.3 SDK

# Context
- **OS, version, SKU and CPU architecture used**: Windows 10 Enterprise | Intel(R) Core(TM) i7
- **Application's .NET Target Framework** : net6.0
- **Device**: Laptop

## Description of the issue
I started from the following example. : provisioning/device/samples/getting started/X509Sample/ProvisioningDeviceClientSample.cs.

When uploading a file, we start by doing this:
![image](https://github.com/Azure/azure-iot-sdk-csharp/assets/133333201/ba54ad8d-d162-4e13-91a8-0f53d425cdd1)

Unfortunately, if we use the example: provisioning/device/samples/getting started/X509Sample/ProvisioningDeviceClientSample.cs. The call to the GetFileUploadSasUriAsync method generates an exception IotHubUnauthorizedAccess (even though the device was successfully provisioned through DPS on the IoT Hub).

After several searches, I came across other examples that allow the file upload to work, and this with authentication via x509 certificate.

It seems that you just need to replace the following lines:
![image](https://github.com/Azure/azure-iot-sdk-csharp/assets/133333201/2e74289d-bd33-40db-a57f-526de2e2bd65)
With:
![image](https://github.com/Azure/azure-iot-sdk-csharp/assets/133333201/22cda9c6-c591-4fdd-b850-343109be3185)

Definition of GetCertificateByThumbprint
![image](https://github.com/Azure/azure-iot-sdk-csharp/assets/133333201/8a76fc33-6ba9-4e97-a387-bf8a174d739d)

It took me some time to get this to work, and I believe that updating the example could greatly help future users. I'm also interested in understanding the exact difference between these two calls...

...and why this difference in the call only impacts the file upload functionality.

Contributor guide

Open the contributing guide

Research direction

Start with provisioning/device/samples/getting started/X509Sample/ProvisioningDeviceClientSample.cs and inspect how the client is created before GetFileUploadSasUriAsync. Compare the certificate-based calls shown in the issue, update the sample so file upload works with X.509 authentication, and verify the example remains consistent with the referenced SDK versions.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.