Skip to content

Commit b791307

Browse files
committed
Updated .NET Entra section
1 parent 177269c commit b791307

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

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

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

15-
##### Entra token credential
15+
##### Security token
1616

17-
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 on 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).
17+
A backend app that uses Microsoft Entra must successfully authenticate and obtain a security token credential before connecting to IoT Hub. This token is passed to a IoT Hub connection method. 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).
1818

19-
To create required Microsoft Entra app parameters for `DefaultAzureCredential`, create a Microsoft Entra app registration that contains your preferred authentication mechanism:
19+
You must set up a Microsoft Entra app that contains your preferred authentication mechanism, which consist of the following:
2020

2121
* Client secret
2222
* Certificate
2323
* Federated identity credential
2424

25-
For more information, see [Quickstart: Register an application with the Microsoft identity platform](/entra/identity-platform/quickstart-register-app).
25+
For more information about setting up a Microsoft Entra app, see [Quickstart: Register an application with the Microsoft identity platform](/entra/identity-platform/quickstart-register-app).
2626

27-
#### Entra app permissions
27+
Microsoft Entra apps may require specific role permissions depending on operations being 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 [Manage access to IoT Hub by using Azure RBAC role assignment](/azure/iot-hub/authenticate-authorize-azure-ad?branch=main#manage-access-to-iot-hub-by-using-azure-rbac-role-assignment).
2828

29-
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](/azure/role-based-access-control/built-in-roles#internet-of-things).
29+
##### Using DefaultAzureCredential
3030

31-
### Connect to IoT Hub
31+
The easiest way to use Microsoft Entra to authenticate a backend applicaiton is to use [DefaultAzureCredential](/dotnet/api/azure.identity.defaultazurecredential), but it's recommended to use a different method in a production envoronment including a specific `TokenCredential` or pared-down `ChainedTokenCredential`. For simplicity, this section describes authentication using `DefaultAzureCredential` and Client secret. For more information about the pros and cons of using `DefaultAzureCredential`, see [Usage guidance for DefaultAzureCredential](/dotnet/azure/sdk/authentication/credential-chains?tabs=dac#usage-guidance-for-defaultazurecredential).
3232

33-
Add these packages and statements to your code to use the Microsoft Entra library.
33+
`DefaultAzureCredential` supports different authentication mechanisms and determines the appropriate credential type based on the environment it's executing in. It attempts to use multiple credential types in an order until it finds a working credential.
3434

35-
Packages:
35+
Microsoft Entra requires these NuGet packages and corresponding `using` statements:
3636

3737
* Azure.Core
3838
* Azure.Identity
3939

40-
Statements:
41-
4240
```csharp
4341
using Azure.Core;
4442
using Azure.Identity;
4543
```
4644

47-
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.
45+
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 result of a successful Microsoft Entra authentication is a security token credential that is passed to an IoT Hub connection method.
4846

4947
```csharp
5048
string clientSecretValue = "xxxxxxxxxxxxxxx";
@@ -58,7 +56,7 @@ Environment.SetEnvironmentVariable("AZURE_TENANT_ID", tenantID);
5856
TokenCredential tokenCredential = new DefaultAzureCredential();
5957
```
6058

61-
The resulting [TokenCredential](/dotnet/api/azure.core.tokencredential) can then be passed to a connect to IoT Hub method for any SDK client that accepts Microsoft Entra/AAD credentials:
59+
The resulting [TokenCredential](/dotnet/api/azure.core.tokencredential) can then be passed to a connect to IoT Hub method for any SDK client that accepts Microsoft Entra credentials:
6260

6361
* [JobClient](/dotnet/api/microsoft.azure.devices.jobclient.create?#microsoft-azure-devices-jobclient-create(system-string-azure-core-tokencredential-microsoft-azure-devices-httptransportsettings))
6462
* [RegistryManager](/dotnet/api/microsoft.azure.devices.registrymanager.create?#microsoft-azure-devices-registrymanager-create(system-string-azure-core-tokencredential-microsoft-azure-devices-httptransportsettings))

0 commit comments

Comments
 (0)