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
Copy file name to clipboardExpand all lines: includes/iot-hub-howto-connect-service-iothub-entra-java.md
+52-12Lines changed: 52 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,25 +11,65 @@ ms.manager: lizross
11
11
ms.date: 11/06/2024
12
12
---
13
13
14
-
### Microsoft Entra client secret credential
14
+
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 general information about setting up and using Microsoft Entra for IoT Hub, see [Control access to IoT Hub by using Microsoft Entra ID](/azure/iot-hub/authenticate-authorize-azure-ad).
15
15
16
-
Use [ClientSecretCredential](/java/api/com.azure.identity.clientsecretcredential) to authenticate an application with Microsoft Entra.
16
+
For an overview of Java SDK authentication, see [Getting started with user authentication on Azure](https://learn.microsoft.com/en-us/azure/developer/java/sdk/authentication/azure-hosted-apps).
17
17
18
-
`ClientSecretCredential` is configured using [ClientSecretCredentialBuilder](/java/api/com.azure.identity.clientsecretcredentialbuilder).
18
+
##### Configure Microsoft Entra app
19
+
20
+
You must set up a Microsoft Entra app that is configured for your preferred authentication credential. The app contains parameters such as client secret that are used by the backend application to authenticate. The available app authentication configurations are:
21
+
22
+
* Client secret
23
+
* Certificate
24
+
* Federated identity credential
25
+
26
+
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?#manage-access-to-iot-hub-by-using-azure-rbac-role-assignment).
27
+
28
+
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).
29
+
30
+
##### Authenticate using DefaultAzureCredential
31
+
32
+
The easiest way to use Microsoft Entra to authenticate a backend application is to use [DefaultAzureCredential](/azure/developer/java/sdk/authentication/credential-chains#defaultazurecredential-overview), but it's recommended to use a different method in a production environment including a specific `TokenCredential` or pared-down `ChainedTokenCredential`. For simplicity, this section describes authentication using `DefaultAzureCredential` and Client secret.
33
+
For more information about the pros and cons of using `DefaultAzureCredential`, see
[DefaultAzureCredential](/java/api/com.azure.identity.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.
37
+
38
+
You can authenticate Microsoft Entra app credentials using [DefaultAzureCredentialBuilder](/java/api/com.azure.identity.defaultazurecredentialbuilder). Save connection parameters such as client secret tenantID, clientID, and client secret values as environmental varaibles. Once the `TokenCredential` is created, pass it to [ServiceClient](https://learn.microsoft.com/en-us/java/api/com.azure.core.annotation.serviceclient) or other builder as the 'credential' parameter.
39
+
40
+
In this example, `DefaultAzureCredentialBuilder` will attempt to authenticate a connection from the list described in [DefaultAzureCredential](/java/api/com.azure.identity.defaultazurecredential). The result of a successful Microsoft Entra authentication is a security token credential that is passed to a constructor.
##### Authenticate using ClientSecretCredentialBuilder
47
+
48
+
You can use [ClientSecretCredentialBuilder](/java/api/com.azure.identity.clientsecretcredentialbuilder) to create a credential using client secret information. If successful, this method returns a [TokenCredential](/java/api/com.azure.core.credential.tokencredential).
49
+
50
+
In this example, Microsoft Entra app registration client secret, client ID, and tenant ID values have been added to environment variables. These environment variables are used by `ClientSecretCredentialBuilder` to build the credential.
51
+
52
+
```java
53
+
// Credentials can be built from types from the Azure Identity library like ClientSecretCredential.
54
+
// The Azure Identity library also defines other implementations of the TokenCredential interface such as
55
+
// DefaultAzureCredential, InteractiveBrowserCredential, and many others.
You can use [ClientCertificateCredential](/java/api/com.azure.identity.clientcertificatecredential) to create a `TokenCredential`using a certificate.
69
+
##### Authenticate using InteractiveBrowserCredential
30
70
31
-
The `TokenCredential` can then be passed to service constructors such as:
71
+
Use [InteractiveBrowserCredential](https://learn.microsoft.com/en-us/java/api/com.azure.identity.interactivebrowsercredential) to authenticate a user sign-in using a web browser.
For more information about Microsoft Entra app registration, see [Quickstart: Register an application with the Microsoft identity platform](/entra/identity-platform/quickstart-register-app).
75
+
For working samples of Microsoft Entra service authentication, see [Role based authentication sample](github.com/Azure/azure-iot-service-sdk-java/tree/main/service/iot-service-samples/role-based-authorization-sample).
Copy file name to clipboardExpand all lines: includes/iot-hub-howto-connect-service-iothub-entra-node.md
+1-5Lines changed: 1 addition & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,16 +53,12 @@ import { DefaultAzureCredential } from "@azure/identity";
53
53
constcredential=newDefaultAzureCredential();
54
54
```
55
55
56
-
The resulting credential token can then be passed to a connection method to connect to IoT Hub method for any SDK client that accepts Microsoft Entra credentials:
56
+
The resulting credential token can then be passed to [fromTokenCredential](/javascript/api/azure-iothub/registry?#azure-iothub-registry-fromtokencredential)to connect to IoT Hub for any SDK client that accepts Microsoft Entra credentials:
Use [fromTokenCredential](/javascript/api/azure-iothub/registry?#azure-iothub-registry-fromtokencredential) to create a service connection to IoT Hub using a Microsoft Entra token credential.
65
-
66
62
`fromTokenCredential` requires two parameters:
67
63
68
64
* The Azure service URL - The Azure service URL should be in the format `{Your Entra domain URL}.azure-devices.net` without a `https://` prefix. For example, `MyAzureDomain.azure-devices.net`.
The resulting [AccessToken](/python/api/azure-core/azure.core.credentials.accesstoken) can then be passed to `from_token_credential` to connect to IoT Hub method for any SDK client that accepts Microsoft Entra credentials:
54
54
55
55
*[IoTHubRegistryManager](/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.
0 commit comments