0
votes

Does anyone know how to create SharedAccessKey for azure IoT hub? I would like to create a default configuration with hostname xxxxx.azure-devices.net and dynamically set the deviceId. How to create with this both parameters the required SharedAccessKey?

1
@silent thank you! I'm looking for a solution inside my code where i starting using the connection. Your example shown it by using the CLI in azure.David Stania
well, what information do you have available in your code? the device symmetric key or the IoT Hub owner key (or another key with registry permissions)?silent
@DavidStania have a look at the docs.microsoft.com/en-us/azure/iot-hub/… and select your case.Roman Kiss

1 Answers

2
votes

You can create the shared access signature using the device sdk or the service sdk. On service sdk side, you can create a generic shared access signature i.e. with resourceuri as {IoT hub name}.azure-devices.net/devices. Check relevant link here.

On device sdk side, you can use the below image algorithm and generate the signature and use it in the code to connect to IoT Hub. For example, here is NodeJS code for device sdk which uses SAS. You can find similar examples in C# too.

enter image description here

So, in the above image u can use policy as iothubowner which has all relevant permissions and with that you can fetch/update/add any device information.