You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use [DefaultAzureCredential](/dotnet/api/azure.identity.defaultazurecredential) to use Microsoft Entra to authenticate a connection to IoT Hub. `DefaultAzureCredential` supports different authentication mechanisms and determines the appropriate credential type based of the environment it is executing in. It attempts to use multiple credential types in an order until it finds a working credential. For more information on setting up Entra for IoT Hub, see [Control access to IoT Hub by using Microsoft Entra ID](/azure/iot-hub/authenticate-authorize-azure-ad).
15
+
Use [DefaultAzureCredential](/dotnet/api/azure.identity.defaultazurecredential) to use Microsoft Entra to authenticate a connection to IoT Hub. `DefaultAzureCredential` supports different authentication mechanisms and determines the appropriate credential type based of the environment it's executing in. It attempts to use multiple credential types in an order until it finds a working credential. For more information on setting up Entra for IoT Hub, see [Control access to IoT Hub by using Microsoft Entra ID](/azure/iot-hub/authenticate-authorize-azure-ad).
16
16
17
-
To create required Entra app parameters to`DefaultAzureCredential`, create an Entra app registration that contains the Azure client secret, client ID, and tenant ID. For more information, see [Quickstart: Register an application with the Microsoft identity platform](/entra/identity-platform/quickstart-register-app).
17
+
To create required Microsoft Entra app parameters for`DefaultAzureCredential`, create a Microsoft Entra app registration that contains your preferred authentication mechanism such as:
18
18
19
-
Entra apps require permissions depending on operations performed:
19
+
* Client secret, client ID, and tenant ID
20
+
* Certificate
20
21
21
-
* Add [IoT Hub Twin Contributor](/azure/role-based-access-control/built-in-roles/internet-of-things#iot-hub-twin-contributor) to enable read and write access to all IoT Hub device and module twins.
22
+
For more information, see [Quickstart: Register an application with the Microsoft identity platform](/entra/identity-platform/quickstart-register-app).
22
23
23
-
In this example, the Entra app registration client secret, client ID, and tenant ID are added to environment variables. These environment variables are used by `DefaultAzureCredential` to authenticate the application.
24
+
Microsoft Entra apps may require permissions depending on operations performed. For example, [IoT Hub Twin Contributor](/azure/role-based-access-control/built-in-roles/internet-of-things#iot-hub-twin-contributor) is required to enable read and write access to a IoT Hub device and module twins. For more information, see [Azure built-in roles](https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#internet-of-things).
25
+
26
+
Add these packages and statements to your code to use the Microsoft Entra library.
27
+
28
+
Packages:
29
+
* Azure.Core
30
+
* Azure.Identity
31
+
32
+
Statements:
33
+
34
+
```csharp
35
+
usingAzure.Core;
36
+
usingAzure.Identity;
37
+
```
38
+
39
+
In this example, Microsoft Entra app registration client secret, client ID, and tenant ID are added to environment variables. These environment variables are used by `DefaultAzureCredential` to authenticate the application.
The resulting [TokenCredential](/dotnet/api/azure.core.tokencredential) can then be passed to an authentication method for any SDK client that accepts Microsft Entra/AAD credentials:
53
+
The resulting [TokenCredential](/dotnet/api/azure.core.tokencredential) can then be passed to an authentication method for any SDK client that accepts Microsoft Entra/AAD credentials:
In this example, the `TokenCredential` is passed to `ServiceClient.Create` to create a [ServiceClient](/dotnet/api/microsoft.azure.devices.serviceclient) connection object.
title: How to connect a service to IoT Hub using Microsoft Entra (Java)
3
+
titleSuffix: Azure IoT Hub
4
+
description: Learn how to connect a service to IoT Hub using Microsoft Entra and the Azure IoT Hub SDK for Java.
5
+
author: kgremban
6
+
ms.author: kgremban
7
+
ms.service: iot-hub
8
+
ms.devlang: java
9
+
ms.topic: include
10
+
ms.manager: lizross
11
+
ms.date: 11/06/2024
12
+
---
13
+
14
+
### Entra client secret credential
15
+
16
+
Use [ClientSecretCredential](https://learn.microsoft.com/en-us/java/api/com.azure.identity.clientsecretcredential) to authenticate an application with Microsoft Entra.
17
+
18
+
`ClientSecretCredential` is configured using [ClientSecretCredentialBuilder](/java/api/com.azure.identity.clientsecretcredentialbuilder).
For more information about Entra app registration, see [Quickstart: Register an application with the Microsoft identity platform](https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-register-app).
title: How to connect a service to IoT Hub using Microsoft Entra (Node.js)
3
+
titleSuffix: Azure IoT Hub
4
+
description: Learn how to connect a service to IoT Hub using Microsoft Entra and the Azure IoT Hub SDK for Node.js.
5
+
author: kgremban
6
+
ms.author: kgremban
7
+
ms.service: iot-hub
8
+
ms.devlang: javascript
9
+
ms.topic: include
10
+
ms.manager: lizross
11
+
ms.date: 11/06/2024
12
+
---
13
+
14
+
For an overview of Node.js SDK authentication, see:
15
+
16
+
*[Getting started with user authentication on Azure](/azure/developer/javascript/how-to/with-authentication/getting-started)
17
+
*[Azure Identity client library for JavaScript](/javascript/api/overview/azure/identity-readme)
18
+
19
+
### Entra token credential
20
+
21
+
Use [DefaultAzureCredential](/javascript/api/@azure/identity/defaultazurecredential) to generate a token. The token will be supplied to `fromTokenCredential`.
22
+
23
+
### Connect to IoT Hub
24
+
25
+
Use [fromTokenCredential](/javascript/api/azure-iothub/registry?#azure-iothub-registry-fromtokencredential) to create a service connection to IoT Hub using an Entra token credential.
26
+
27
+
`fromTokenCredential` requires two parameters:
28
+
29
+
* hostname - The Azure service URL
30
+
* tokenCredential - The Azure credential token
31
+
32
+
In this example, the Azure credential is obtained using `DefaultAzureCredential`. THe Azure domain URL and credential are then supplied to `KeyClient`.
title: How to connect a service to IoT Hub using Microsoft Entra (Python)
3
+
titleSuffix: Azure IoT Hub
4
+
description: Learn how to connect a service to IoT Hub using Microsoft Entra and the Azure IoT Hub SDK for Python.
5
+
author: kgremban
6
+
ms.author: kgremban
7
+
ms.service: iot-hub
8
+
ms.devlang: python
9
+
ms.topic: include
10
+
ms.manager: lizross
11
+
ms.date: 11/06/2024
12
+
---
13
+
14
+
For an overview of Python SDK authentication, see [Authenticate Python apps to Azure services by using the Azure SDK for Python](https://learn.microsoft.com/en-us/azure/developer/python/sdk/authentication/overview)
15
+
16
+
### Entra token credential
17
+
18
+
You must generate and supply a token credential to `from_token_credential`.
19
+
20
+
[DefaultAzureCredential](/azure/developer/python/sdk/authentication/overview#use-defaultazurecredential-in-an-application) is the easiest way to generate a token. You can also use credential chains to generate a token. For more information, see [Credential chains in the Azure Identity client library for Python](/azure/developer/python/sdk/authentication/credential-chains).
21
+
22
+
### Connect to IoT Hub
23
+
24
+
Use [from_token_credential](/python/api/azure-iot-hub/azure.iot.hub.iothubregistrymanager?#azure-iot-hub-iothubregistrymanager-from-token-credential) to create a service connection to IoT Hub using an Entra token credential.
25
+
26
+
`from_token_credential` requires two parameters:
27
+
28
+
* The Azure service URL
29
+
* The Azure credential token
30
+
31
+
In this example, the Azure credential is obtained using `DefaultAzureCredential`. THe Azure domain URL and credential are then supplied to `BlobServiceClient`.
0 commit comments