Azure-docs: Unauthorized error message

Created on 28 Aug 2018  Â·  6Comments  Â·  Source: MicrosoftDocs/azure-docs

Hello, when I run this example, I'm getting the following error. My deviceId and connection string are correct. I can successfully invoke the method from Azure (IOTHub/Devices). Any idea what is causing this ? Thanks Microsoft.Azure.Devices.Common.Exceptions.UnauthorizedException
HResult=0x80131500
Message={"Message":"{\"errorCode\":401002,\"trackingId\":\"84f2a56e7ab248f899af0a413f7b1a59-G:6-TimeStamp:08/28/2018 15:34:17\",\"message\":\"Unauthorized\",\"timestampUtc\":\"2018-08-28T15:34:17.5432324Z\"}","ExceptionMessage":""}
Source=Microsoft.Azure.Devices
StackTrace:
at Microsoft.Azure.Devices.HttpClientHelper.<ExecuteAsync>d__35.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Devices.HttpClientHelper.<PostAsync>d__262.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at back_end_application.BackEndApplication.<InvokeMethod>d__2.MoveNext() in C:\Users\bruem\Downloads\azure-iot-samples-csharp-master\azure-iot-samples-csharp-master\iot-hub\Quickstarts\back-end-application\BackEndApplication.cs:line 28
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at back_end_application.BackEndApplication.Main(String[] args) in C:\Users\bruem\Downloads\azure-iot-samples-csharp-master\azure-iot-samples-csharp-master\iot-hub\Quickstarts\back-end-application\BackEndApplication.cs:line 41


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri2 cxp in-progress iot-husvc product-question triaged

Most helpful comment

@fbruemmer73 thank you for your feedback. Can you double check the following?

Open the SimulatedDevice.cs file in a text editor of your choice.
Replace the value of the s_connectionString variable with the device connection string you made a note of previously. Then save your changes to SimulatedDevice.cs file.

Open the BackEndApplication.cs file in a text editor of your choice.
Replace the value of the s_connectionString variable with the service connection string you made a note of previously. Then save your changes to the BackEndApplication.cs file.

This is, in SimulatedDevice.cs you need to use the device connection string while in BackEndApplication.cs you should use service connection string.

If you were doing it correctly can you paste here the device connection string and service connection string so I can have a look? Please note that if you share here the connection strings you will need to create them again for security reasons, I just want to make sure that the format is correct :).

Thank you!

All 6 comments

@fbruemmer73 thank you for your feedback. Can you double check the following?

Open the SimulatedDevice.cs file in a text editor of your choice.
Replace the value of the s_connectionString variable with the device connection string you made a note of previously. Then save your changes to SimulatedDevice.cs file.

Open the BackEndApplication.cs file in a text editor of your choice.
Replace the value of the s_connectionString variable with the service connection string you made a note of previously. Then save your changes to the BackEndApplication.cs file.

This is, in SimulatedDevice.cs you need to use the device connection string while in BackEndApplication.cs you should use service connection string.

If you were doing it correctly can you paste here the device connection string and service connection string so I can have a look? Please note that if you share here the connection strings you will need to create them again for security reasons, I just want to make sure that the format is correct :).

Thank you!

Thank you so much for the quick response. I must have missed the SERVICE connection string part since I was using the device connection string in both apps. This works now. I really appreciate your help.

You are very welcome @fbruemmer73 it was a pleasure to guide you in the right direction :)!

We will now proceed to close this thread. If there are further questions regarding this matter, please tag me in your reply. We will gladly continue the discussion and we will reopen the issue.

Hi Sergaz, i also facing the same situation with the above issue. My issue is have created deviceID on my portal and Azure Hub name does exist. I have used Azure CLI to get my service connectionString, but i keep getting DeviceNOTFound exception, what could be reason for this? Please assist me for clarity in order to help others here in my organisation.

@gcogco10 This issue is resolved long back, and you might be facing an issue for some other reason.
I think this question would be better suited for MSDN or Stack Overflow where there is a development community that can help.

For the people finding this thread through Google: my mistake was that on the service side, I used the connection string of the IoT device. This results in the same error. You need to use the connection string of the IoT Hub (in which the IoT Device exists) instead. :)

Was this page helpful?
0 / 5 - 0 ratings