Skip to content

Commit 0b6985f

Browse files
committed
Added Entra articles
1 parent bb5d580 commit 0b6985f

5 files changed

+146
-8
lines changed

includes/iot-hub-howto-connect-service-iothub-entra-dotnet.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,31 @@ ms.date: 11/06/2024
1212
ms.custom: mqtt, devx-track-csharp, devx-track-dotnet
1313
---
1414

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 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).
1616

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:
1818

19-
Entra apps require permissions depending on operations performed:
19+
* Client secret, client ID, and tenant ID
20+
* Certificate
2021

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).
2223

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+
using Azure.Core;
36+
using Azure.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.
2440

2541
```csharp
2642
string clientSecretValue = "xxxxxxxxxxxxxxx";
@@ -34,12 +50,12 @@ Environment.SetEnvironmentVariable("AZURE_TENANT_ID", tenantID);
3450
TokenCredential tokenCredential = new DefaultAzureCredential();
3551
```
3652

37-
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:
3854

3955
* [JobClient](/dotnet/api/microsoft.azure.devices.jobclient.create?#microsoft-azure-devices-jobclient-create(system-string-azure-core-tokencredential-microsoft-azure-devices-httptransportsettings))
4056
* [RegistryManager](/dotnet/api/microsoft.azure.devices.registrymanager.create?#microsoft-azure-devices-registrymanager-create(system-string-azure-core-tokencredential-microsoft-azure-devices-httptransportsettings))
4157
* [DigitalTwinClient](/dotnet/api/microsoft.azure.devices.digitaltwinclient)
42-
* [ServiceClient](https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.devices.serviceclient.create?view=azure-dotnet#microsoft-azure-devices-serviceclient-create(system-string-azure-core-tokencredential-microsoft-azure-devices-transporttype-microsoft-azure-devices-serviceclienttransportsettings-microsoft-azure-devices-serviceclientoptions))
58+
* [ServiceClient](/dotnet/api/microsoft.azure.devices.serviceclient.create?#microsoft-azure-devices-serviceclient-create(system-string-azure-core-tokencredential-microsoft-azure-devices-transporttype-microsoft-azure-devices-serviceclienttransportsettings-microsoft-azure-devices-serviceclientoptions))
4359

4460
In this example, the `TokenCredential` is passed to `ServiceClient.Create` to create a [ServiceClient](/dotnet/api/microsoft.azure.devices.serviceclient) connection object.
4561

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
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).
19+
20+
```java
21+
TokenCredential clientSecretCredential = new ClientSecretCredentialBuilder().tenantId(tenantId)
22+
.clientId(clientId)
23+
.clientSecret(clientSecret)
24+
.build();
25+
```
26+
27+
### Entra client certificate credential
28+
29+
You can use [ClientCertificateCredential](/java/api/com.azure.identity.clientcertificatecredential) to create a `TokenCredential` using a certicate.
30+
31+
The `TokenCredential` can then be passed to service constructors such as:
32+
33+
* [DeviceTwin](https://learn.microsoft.com/en-us/java/api/com.microsoft.azure.sdk.iot.service.devicetwin.devicetwin?view=azure-java-stable#com-microsoft-azure-sdk-iot-service-devicetwin-devicetwin-devicetwin(java-lang-string-com-azure-core-credential-tokencredential))
34+
35+
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).
36+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
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`.
33+
34+
```javascript
35+
import { DefaultAzureCredential } from "@azure/identity";
36+
import { KeyClient } from "@azure/keyvault-keys";
37+
38+
// Configure vault URL
39+
const vaultUrl = "https://<your-unique-keyvault-name>.vault.azure.net";
40+
// Azure SDK clients accept the credential as a parameter
41+
const credential = new DefaultAzureCredential();
42+
// Create authenticated client
43+
const client = new KeyClient(vaultUrl, credential);
44+
```
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
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`.
32+
33+
```python
34+
from azure.identity import DefaultAzureCredential
35+
from azure.storage.blob import BlobServiceClient
36+
37+
# Acquire a credential object
38+
credential = DefaultAzureCredential()
39+
40+
blob_service_client = BlobServiceClient(
41+
account_url="https://<my_account_name>.blob.core.windows.net",
42+
credential=credential)
43+
```

includes/iot-hub-howto-module-twins-dotnet.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ You can connect a backend service to IoT Hub using the following methods:
157157

158158
* Shared access policy
159159
* Microsoft Entra
160-
* X.509 certificate
161160

162161
#### Connect using a shared access policy
163162

0 commit comments

Comments
 (0)