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
To connect a device to IoT Hub using an X.509 certificate:
16
+
17
+
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).
18
+
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.
20
+
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.
For more information about certificate authentication, see:
48
+
49
+
*[Authenticate identities with X.509 certificates](/azure/iot-hub/authenticate-authorize-x509)
50
+
*[Tutorial: Create and upload certificates for testing](/azure/iot-hub/tutorial-x509-test-certs)
51
+
52
+
##### Code samples
53
+
54
+
For working samples of device X.509 certificate authentication, see:
55
+
56
+
*[Connect with X.509 certificate](https://github.com/Azure/azure-iot-sdk-csharp/tree/main/iothub/device/samples/how%20to%20guides/X509DeviceCertWithChainSample)
title: How to connect a device to IoT Hub using a certificate (Java)
3
+
titleSuffix: Azure IoT Hub
4
+
description: Learn how to connect a device to IoT Hub using a certificate 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: 12/12/2024
12
+
---
13
+
14
+
To connect a device to IoT Hub using an X.509 certificate:
15
+
16
+
1. Build the [SSLContext](https://docs.oracle.com/javase/8/docs/api/javax/net/ssl/SSLContext.html) object using [buildSSLContext](https://hc.apache.org/httpcomponents-core-4.4.x/current/httpcore/apidocs/org/apache/http/ssl/SSLContextBuilder.html).
17
+
1. Add the `SSLContext` information to a [ClientOptions](/java/api/com.microsoft.azure.sdk.iot.device.clientoptions) object.
18
+
1. Call [DeviceClient](/java/api/com.microsoft.azure.sdk.iot.device.deviceclient?#com-microsoft-azure-sdk-iot-device-deviceclient-deviceclient(java-lang-string-com-microsoft-azure-sdk-iot-device-iothubclientprotocol-com-microsoft-azure-sdk-iot-device-clientoptions)) using the `ClientOptions` information to create the device-to-IoT Hub connection.
19
+
20
+
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("PUBLICKEY")` to read a public key certificate string environment variable.
title: How to connect a device to IoT Hub using a certificate (Node.js)
3
+
titleSuffix: Azure IoT Hub
4
+
description: Learn how to connect a device to IoT Hub using a certificate and the Azure IoT Hub SDK for Node.js.
5
+
author: kgremban
6
+
ms.author: kgremban
7
+
ms.service: iot-hub
8
+
ms.devlang: node
9
+
ms.topic: include
10
+
ms.manager: lizross
11
+
ms.date: 12/12/2024
12
+
---
13
+
14
+
The X.509 certificate is attached to the device-to-IoT Hub connection transport.
15
+
16
+
To configure a device-to-IoT Hub connection using an X.509 certificate:
17
+
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 is added to `DeviceClientOptions`. For example: `HostName=xxxxx.azure-devices.net;DeviceId=Device-1;SharedAccessKey=xxxxxxxxxxxxx;x509=true`.
19
+
1. Configure a JSON variable with certificate details and pass it to [DeviceClientOptions](/javascript/api/azure-iot-device/deviceclientoptions).
20
+
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.
21
+
1. Call [open](/javascript/api/azure-iothub/client?#azure-iothub-client-open) to open the connection from the device to IoT Hub.
22
+
23
+
This example shows certificate configuration information within a JSON variable. The certification configuration `options` are passed to `setOptions` and the connection is opened using `open`.
24
+
25
+
```javascript
26
+
var options = {
27
+
cert: myX509Certificate,
28
+
key: myX509Key,
29
+
passphrase: passphrase,
30
+
http: {
31
+
receivePolicy: {
32
+
interval:10
33
+
}
34
+
}
35
+
}
36
+
client.setOptions(options, callback);
37
+
client.open(connectCallback);
38
+
```
39
+
40
+
For more information about certificate authentication, see:
41
+
42
+
*[Authenticate identities with X.509 certificates](/azure/iot-hub/authenticate-authorize-x509)
43
+
*[Create and upload certificates for testing](/azure/iot-hub/tutorial-x509-test-certs)
44
+
45
+
##### Code sample
46
+
47
+
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).
title: How to connect a device to IoT Hub using a certificate (Python)
3
+
titleSuffix: Azure IoT Hub
4
+
description: Learn how to connect a device to IoT Hub using a certificate 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: 12/06/2024
12
+
---
13
+
14
+
To connect a device to IoT Hub using an X.509 certificate:
15
+
16
+
1. Use [create_from_x509_certificate](/python/api/azure-iot-device/azure.iot.device.iothubdeviceclient?#azure-iot-device-iothubdeviceclient-create-from-x509-certificate) to add the X.509 certificate parameters
17
+
1. Call [connect](/python/api/azure-iot-device/azure.iot.device.iothubdeviceclient?#azure-iot-device-iothubdeviceclient-connect) to connect the device client
18
+
19
+
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 `os.getenv("HOSTNAME")` to read the host name environment variable.
20
+
21
+
```python
22
+
# The Azure IoT hub name
23
+
hostname ="xxxxx.azure-devices.net"
24
+
25
+
# The device that has been created on the portal using X509 CA signing or self-signing capabilities
For more information about certificate authentication, see:
50
+
51
+
*[Authenticate identities with X.509 certificates](/azure/iot-hub/authenticate-authorize-x509)
52
+
*[Tutorial: Create and upload certificates for testing](/azure/iot-hub/tutorial-x509-test-certs)
53
+
54
+
##### Code samples
55
+
56
+
For working samples of device X.509 certificate authentication, see the examples whose file names end in x509 at [Async hub scenarios](https://github.com/Azure/azure-iot-sdk-python/tree/main/samples/async-hub-scenarios).
Call [CreateFromConnectionString](/dotnet/api/microsoft.azure.devices.client.deviceclient.createfromconnectionstring?#microsoft-azure-devices-client-deviceclient-createfromconnectionstring(system-string)) to connect to the device. Pass the device primary connection string.
35
46
@@ -109,21 +120,47 @@ You can create a backend service to receive file upload notification messages fr
109
120
110
121
The [ServiceClient](/dotnet/api/microsoft.azure.devices.serviceclient) class contains methods that services can use to receive file upload notifications.
111
122
112
-
To receive file upload notification:
123
+
### Add service NuGet Package
113
124
114
-
1. Call [CreateFromConnectionString](/dotnet/api/microsoft.azure.devices.serviceclient.createfromconnectionstring) to connect to IoT hub. Pass the IoT hub primary connection string.
115
-
1. Create a [CancellationToken](/dotnet/api/azure.core.httpmessage.cancellationtoken?#azure-core-httpmessage-cancellationtoken).
116
-
1. Call [GetFileNotificationReceiver](/dotnet/api/microsoft.azure.devices.serviceclient.getfilenotificationreceiver?#microsoft-azure-devices-serviceclient-getfilenotificationreceiver) to create a notification receiver.
117
-
1. Use a loop with [ReceiveAsync](/dotnet/api/microsoft.azure.devices.receiver-1.receiveasync?#microsoft-azure-devices-receiver-1-receiveasync(system-threading-cancellationtoken)) to wait for the file upload notification.
125
+
Backend service applications require the **Microsoft.Azure.Devices** NuGet package.
126
+
127
+
### Connect to IoT hub
128
+
129
+
You can connect a backend service to IoT Hub using the following methods:
Connect a backend application to a device using [CreateFromConnectionString](/dotnet/api/microsoft.azure.devices.registrymanager.createfromconnectionstring). Your application needs **service connect** permission. Supply this shared access policy connection string as a parameter to `fromConnectionString`. For more information about shared access policies, see [Control access to IoT Hub with shared access signatures](/azure/iot-hub/authenticate-authorize-sas).
1. Create a [CancellationToken](/dotnet/api/azure.core.httpmessage.cancellationtoken?#azure-core-httpmessage-cancellationtoken).
158
+
1. Call [GetFileNotificationReceiver](/dotnet/api/microsoft.azure.devices.serviceclient.getfilenotificationreceiver?#microsoft-azure-devices-serviceclient-getfilenotificationreceiver) to create a notification receiver.
159
+
1. Use a loop with [ReceiveAsync](/dotnet/api/microsoft.azure.devices.receiver-1.receiveasync?#microsoft-azure-devices-receiver-1-receiveasync(system-threading-cancellationtoken)) to wait for the file upload notification.
The SDK includes this [file upload receiver sample](https://github.com/Azure/azure-iot-sdk-csharp/blob/86065001a92fedb42877722c6a57ae37e45eed30/iothub/service/samples/getting%20started/FileUploadNotificationReceiverSample/FileUploadNotificationReceiverSample.cs).
0 commit comments