Skip to content

Commit ede8014

Browse files
committed
Added auth content and review feedback edits
1 parent efd734e commit ede8014

7 files changed

+84
-46
lines changed

includes/iot-hub-howto-auth-device-cert-dotnet.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ To connect a device to IoT Hub using an X.509 certificate:
1616

1717
1. Use [DeviceAuthenticationWithX509Certificate](/dotnet/api/microsoft.azure.devices.client.deviceauthenticationwithx509certificate) to create an object that contains device and certificate information. `DeviceAuthenticationWithX509Certificate` is passed as the second parameter to `DeviceClient.Create` (step 2).
1818

19-
1. Use [DeviceClient.Create](/dotnet/api/microsoft.azure.devices.client.deviceclient.create?view=azure-dotnet&#microsoft-azure-devices-client-deviceclient-create(system-string-microsoft-azure-devices-client-iauthenticationmethod-microsoft-azure-devices-client-transporttype)) to connect the device to IoT Hub using an X.509 certificate.
19+
1. Use [DeviceClient.Create](/dotnet/api/microsoft.azure.devices.client.deviceclient.create?&#microsoft-azure-devices-client-deviceclient-create(system-string-microsoft-azure-devices-client-iauthenticationmethod-microsoft-azure-devices-client-transporttype)) to connect the device to IoT Hub using an X.509 certificate.
2020

21-
In this example, the device and certificate information are populated in the `auth` `DeviceAuthenticationWithX509Certificate` object that is passed to `DeviceClient.Create`.
21+
In this example, device and certificate information is populated in the `auth` `DeviceAuthenticationWithX509Certificate` object that is passed to `DeviceClient.Create`.
22+
23+
This example shows certificate input parameter values as local variables for clarity. In a production system, store sensitive input parameters in environment variables or another more secure storage location. For example, use `Environment.GetEnvironmentVariable("HOSTNAME")` to read the host name environment variable.
2224

2325
```csharp
2426
RootCertPath = "~/certificates/certs/sensor-thl-001-device.cert.pem";
@@ -46,10 +48,6 @@ For more information about certificate authentication, see:
4648

4749
* [Authenticate identities with X.509 certificates](/azure/iot-hub/authenticate-authorize-x509)
4850
* [Tutorial: Create and upload certificates for testing](/azure/iot-hub/tutorial-x509-test-certs)
49-
* [X509Certificate2Collection](/dotnet/api/system.security.cryptography.x509certificates.x509certificate2collection)
50-
* [X509Certificate2](/dotnet/api/system.security.cryptography.x509certificates.x509certificate2)
51-
* [Tutorial: Provision multiple X.509 devices using enrollment groups](/azure/iot-dps/tutorial-custom-hsm-enrollment-group-x509?pivots=programming-language-csharp)
52-
* [OpenSSL CA](https://openssl-ca.readthedocs.io/)
5351

5452
##### Code samples
5553

includes/iot-hub-howto-auth-device-cert-java.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ For more information about certificate authentication, see:
4242

4343
* [Authenticate identities with X.509 certificates](/azure/iot-hub/authenticate-authorize-x509)
4444
* [Tutorial: Create and upload certificates for testing](/azure/iot-hub/tutorial-x509-test-certs)
45-
* [Tutorial: Provision multiple X.509 devices using enrollment groups](/azure/iot-dps/tutorial-custom-hsm-enrollment-group-x509?pivots=programming-language-java)
46-
* [OpenSSL CA](https://openssl-ca.readthedocs.io/)
4745

4846
##### Code samples
4947

includes/iot-hub-howto-auth-device-cert-node.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to connect a device to IoT Hub using a certificate and th
55
author: kgremban
66
ms.author: kgremban
77
ms.service: iot-hub
8-
ms.devlang: python
8+
ms.devlang: node
99
ms.topic: include
1010
ms.manager: lizross
1111
ms.date: 12/12/2024
@@ -15,7 +15,7 @@ The X.509 certificate is attached to the device-to-IoT Hub connection transport.
1515

1616
To configure a device-to-IoT Hub connection using an X.509 certificate:
1717

18-
1. Call [fromConnectionString](/javascript/api/azure-iothub/client?#azure-iothub-client-fromconnectionstring) to add the device connection string and transport type.
18+
1. Call [fromConnectionString](/javascript/api/azure-iothub/client?#azure-iothub-client-fromconnectionstring) to add the device connection string and transport type. Add `x509=true` to the device connection string to indicate that a certificate will be added to `DeviceClientOptions`. For example: `HostName=xxxxx.azure-devices.net;DeviceId=Device-1;SharedAccessKey=xxxxxxxxxxxxx;x509=true`.
1919
1. Configure a JSON variable with certificate details and pass it to [DeviceClientOptions](/javascript/api/azure-iot-device/deviceclientoptions).
2020
1. Call [setOptions](/javascript/api/azure-iot-device/client?#azure-iot-device-client-setoptions-1) to add an X.509 certificate and key (and optionally, passphrase) to the client transport.
2121
1. Call [open](/javascript/api/azure-iothub/client?#azure-iothub-client-open) to open the connection from the device to IoT Hub.
@@ -41,9 +41,7 @@ For more information about certificate authentication, see:
4141

4242
* [Authenticate identities with X.509 certificates](/azure/iot-hub/authenticate-authorize-x509)
4343
* [Create and upload certificates for testing](/azure/iot-hub/tutorial-x509-test-certs)
44-
* [Tutorial: Provision multiple X.509 devices using enrollment groups](/azure/iot-dps/tutorial-custom-hsm-enrollment-group-x509?pivots=programming-language-nodejs)
45-
* [OpenSSL CA](https://openssl-ca.readthedocs.io/)
4644

47-
##### Code samples
45+
##### Code sample
4846

4947
For a working sample of device X.509 certificate authentication, see [Simple sample device X.509](https://github.com/Azure/azure-iot-sdk-node/blob/main/device/samples/javascript/simple_sample_device_x509.js).

includes/iot-hub-howto-auth-device-cert-python.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ For more information about certificate authentication, see:
5151

5252
* [Authenticate identities with X.509 certificates](/azure/iot-hub/authenticate-authorize-x509)
5353
* [Tutorial: Create and upload certificates for testing](/azure/iot-hub/tutorial-x509-test-certs)
54-
* [Tutorial: Provision multiple X.509 devices using enrollment groups](/azure/iot-dps/tutorial-custom-hsm-enrollment-group-x509?pivots=programming-language-python)
55-
* [OpenSSL CA](https://openssl-ca.readthedocs.io/)
5654

5755
##### Code samples
5856

includes/iot-hub-howto-file-upload-dotnet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Follow this procedure to upload a file from a device to IoT hub:
2929
1. Upload the file to Azure storage
3030
1. Notify IoT hub of the file upload status
3131

32-
### Connect to the device
32+
### Connect a device to IoT Hub
3333

3434
A device app can authenticate with IoT Hub using the following methods:
3535

includes/iot-hub-howto-file-upload-java.md

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.author: kgremban
77
ms.service: azure-iot-hub
88
ms.devlang: java
99
ms.topic: include
10-
ms.date: 07/01/2024
10+
ms.date: 12/12/2024
1111
ms.custom: amqp, mqtt, devx-track-java, devx-track-extended-java
1212
---
1313

@@ -129,18 +129,63 @@ This section describes how to receive a file upload notification in a backend ap
129129

130130
The [ServiceClient](/java/api/com.azure.core.annotation.serviceclient) class contains methods that services can use to receive file upload notifications.
131131

132+
### Add import statements
133+
134+
Add these **import** statements to use the Azure IoT Java SDK and exception handler.
135+
136+
```java
137+
import com.microsoft.azure.sdk.iot.service.*;
138+
import java.io.IOException;
139+
import java.net.URISyntaxException;
140+
```
141+
132142
### Connect to the IoT Hub
133143

134-
Create a `IotHubServiceClientProtocol` object. The connection uses the `AMQPS` protocol.
144+
You can connect a backend service to IoT Hub using the following methods:
145+
146+
* Shared access policy
147+
* Microsoft Entra
148+
149+
[!INCLUDE [iot-authentication-service-connection-string.md](iot-authentication-service-connection-string.md)]
150+
151+
#### Connect using a shared access policy
152+
153+
##### Define the connection protocol
154+
155+
Use [IotHubServiceClientProtocol](/java/api/com.microsoft.azure.sdk.iot.service.iothubserviceclientprotocol) to define the application-layer protocol used by the service client to communicate with an IoT Hub.
156+
157+
`IotHubServiceClientProtocol` only accepts the `AMQPS` or `AMQPS_WS` enum.
158+
159+
```java
160+
private static final IotHubServiceClientProtocol protocol =
161+
IotHubServiceClientProtocol.AMQPS;
162+
```
163+
164+
##### Create the ServiceClient object
165+
166+
Create the [ServiceClient](/java/api/com.azure.core.annotation.serviceclient) object, supplying the Iot Hub connection string and protocol.
167+
168+
To invoke a direct method on a device through IoT Hub, your service needs the **service connect** permission. By default, every IoT Hub is created with a shared access policy named **service** that grants this permission.
169+
170+
As a parameter to the `ServiceClient` constructor, supply the **service** shared access policy. For more information about shared access policies, see [Control access to IoT Hub with shared access signatures](/azure/iot-hub/authenticate-authorize-sas).
135171

136-
Call `createFromConnectionString` to connect to IoT hub. Pass the IoT hub primary connection string.
172+
```java
173+
String iotHubConnectionString = "HostName=xxxxx.azure-devices.net;SharedAccessKeyName=service;SharedAccessKey=xxxxxxxxxxxxxxxxxxxxxxxx";
174+
private static final ServiceClient serviceClient (iotHubConnectionString, protocol);
175+
```
176+
177+
##### Open the connection between application and IoT Hub
178+
179+
[open](/java/api/com.microsoft.azure.sdk.iot.service.serviceclient?#com-microsoft-azure-sdk-iot-service-serviceclient-open()) the AMQP sender connection. This method creates the connection between the application and IoT Hub.
137180

138181
```java
139-
private static final String connectionString = "{IoT hub primary connection string}";
140-
private static final IotHubServiceClientProtocol protocol = IotHubServiceClientProtocol.AMQPS;
141-
ServiceClient sc = ServiceClient.createFromConnectionString(connectionString, protocol);
182+
serviceClient.open();
142183
```
143184

185+
#### Connect using Microsoft Entra
186+
187+
[!INCLUDE [iot-hub-howto-connect-service-iothub-entra-java](iot-hub-howto-connect-service-iothub-entra-java.md)]
188+
144189
### Check for file upload status
145190

146191
To check for file upload status:
@@ -152,7 +197,7 @@ To check for file upload status:
152197
For example:
153198

154199
```java
155-
FileUploadNotificationReceiver receiver = sc.getFileUploadNotificationReceiver();
200+
FileUploadNotificationReceiver receiver = serviceClient.getFileUploadNotificationReceiver();
156201
receiver.open();
157202
FileUploadNotification fileUploadNotification = receiver.receive(2000);
158203

includes/iot-hub-howto-file-upload-node.md

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ The SDK includes an [upload to blob advanced](https://github.com/Azure/azure-iot
226226

227227
## Create a backend application
228228

229-
This section describes how to receive file upload notification in a backend application.
229+
This section describes how to receive file upload notifications in a backend application.
230+
231+
The [ServiceClient](/javascript/api/azure-iothub/client) class contains methods that services can use to receive file upload notifications.
230232

231233
### Install service SDK package
232234

@@ -236,41 +238,36 @@ Run this command to install **azure-iothub** on your development machine:
236238
npm install azure-iothub --save
237239
```
238240

239-
## Receive file upload notification in a backend application
241+
### Connect to IoT hub
240242

241-
You can create a backend application to check the IoT hub service client for device file upload notifications.
243+
You can connect a backend service to IoT Hub using the following methods:
242244

243-
To create a file upload notification application:
245+
* Shared access policy
246+
* Microsoft Entra
244247

245-
1. Connect to the IoT hub service client
246-
1. Check for a file upload notification
248+
[!INCLUDE [iot-authentication-service-connection-string.md](iot-authentication-service-connection-string.md)]
247249

248-
### Connect to the IoT hub service client
250+
#### Connect using a shared access policy
249251

250-
The [ServiceClient](/javascript/api/azure-iothub/client) class contains methods that services can use to receive file upload notifications.
252+
Use [fromConnectionString](/javascript/api/azure-iothub/client?#azure-iothub-client-fromconnectionstring) to connect to IoT hub.
251253

252-
Connect to IoT hub using [fromConnectionString](/javascript/api/azure-iothub/client?#azure-iothub-client-fromconnectionstring). Pass the IoT hub primary connection string.
254+
To upload a file from a device, your service needs the **service connect** permission. By default, every IoT Hub is created with a shared access policy named **service** that grants this permission.
255+
256+
As a parameter to `CreateFromConnectionString`, supply the **service** shared access policy connection string. For more information about shared access policies, see [Control access to IoT Hub with shared access signatures](/azure/iot-hub/authenticate-authorize-sas).
253257

254258
```javascript
255-
const Client = require('azure-iothub').Client;
256-
const connectionString = "{IoT hub primary connection string}";
257-
const serviceClient = Client.fromConnectionString(connectionString);
259+
var Client = require('azure-iothub').Client;
260+
var connectionString = '{IoT hub shared access policy connection string}';
261+
var client = Client.fromConnectionString(connectionString);
258262
```
259263

260-
[Open](/javascript/api/azure-iothub/client?#azure-iothub-client-open-1) the connection to IoT hub.
264+
#### Connect using Microsoft Entra
261265

262-
```javascript
263-
//Open the connection to IoT hub
264-
serviceClient.open(function (err) {
265-
if (err) {
266-
console.error('Could not connect: ' + err.message);
267-
} else {
268-
console.log('Service client connected');
269-
```
266+
[!INCLUDE [iot-hub-howto-connect-service-iothub-entra-node](iot-hub-howto-connect-service-iothub-entra-node.md)]
270267

271-
### Check for a file upload notification
268+
### Create a file upload notification callback receiver
272269

273-
To check for file upload notifications:
270+
To create a file upload notification callback receiver:
274271

275272
1. Call [getFileNotificationReceiver](/javascript/api/azure-iothub/client?#azure-iothub-client-getfilenotificationreceiver). Supply the name of a file upload callback method that are called when notification messages are received.
276273
1. Process file upload notifications in the callback method.
@@ -296,3 +293,7 @@ if (err) {
296293
});
297294
}
298295
```
296+
297+
#### SDK file upload notification sample
298+
299+
The SDK includes a [file upload](https://github.com/Azure/azure-iot-sdk-node/blob/main/e2etests/test/file_upload.js) sample.

0 commit comments

Comments
 (0)