Authenticating `IoTHubRegistryManager` using the `from_token_credential` constructor
See original GitHub issueProblem
-
Hi azure team; we have a need to manage several IoT hubs; sending cloud to device messages for eg. So far, we have been using the
from_connection_string
constructor to do this. However this is a bit clunky as it requires us to have the connection string encoded as a secret for each of the IoT hubs. -
We are instead hoping to use
from_token_credential
to achieve authentication to all the IoT hubs within a subscription.
Attempt and error faced
We are following the instructions as given here to try out C2D messaging for a simulated device; the only difference being
# This line is removed
registry_manager = IoTHubRegistryManager(CONNECTION_STRING)
# This is added
from azure.identity import EnvironmentCredential
credential = EnvironmentCredential()
registry_manager = IoTHubRegistryManager.from_token_credential(
url="azure-simlab1.azure-devices.net",
token_credential=credential.get_token(os.environ.get("scopes")),
)
Upon running the command; it either
- Throws when an invalid scope is passed;
- Or just hangs; the simulated device does not receive a message.
- It works perfectly fine if we switch back to the connection string method.
Question
- What is the correct scope for such a request?
- Is the
EnvironmentCredential
the correct approach?
Thanks! Sahil
Issue Analytics
- State:
- Created 2 years ago
- Comments:22 (12 by maintainers)
Top Results From Across the Web
azure.iot.hub.IoTHubRegistryManager class | Microsoft Learn
Creates a module identity for a device on IoTHub using X509 authentication. delete_device. Deletes a device identity from IoTHub. delete_module. Deletes a ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@vishnureddy17 that worked! Thanks for the quick turnaround, really appreciate it 😃
Here is the code that worked
@sgoyal1012 , if you update your azure-iot-hub to version 2.5.0, you should be able to send the messages. Please let me know if this resolves it, thanks!