Skip to content

Commit 856bb11

Browse files
committed
connection string and delete/disable steps
1 parent 5e64b1d commit 856bb11

File tree

2 files changed

+97
-27
lines changed

2 files changed

+97
-27
lines changed

articles/azure-maps/tutorial-iot-hub-maps.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ To learn more about how to send device-to-cloud telemetry, and the other way aro
279279
[geofence JSON data file]: https://raw.githubusercontent.com/Azure-Samples/iothub-to-azure-maps-geofencing/master/src/Data/geofence.json?token=AKD25BYJYKDJBJ55PT62N4C5LRNN4
280280
[Plug and Play schema for geospatial data]: https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v1-preview/schemas/geospatial.md
281281
[Postman]: https://www.postman.com/
282-
[register a new device in the IoT hub]: ../iot-hub/iot-hub-create-through-portal.md#register-a-new-device-in-the-iot-hub
282+
[register a new device in the IoT hub]: ../iot-hub/create-connect-device.md
283283
[rentalCarSimulation]: https://github.com/Azure-Samples/iothub-to-azure-maps-geofencing/tree/master/src/rentalCarSimulation
284284
[resource group]: ../azure-resource-manager/management/manage-resource-groups-portal.md#create-resource-groups
285285
[the root of the sample]: https://github.com/Azure-Samples/iothub-to-azure-maps-geofencing

articles/iot-hub/create-connect-device.md

Lines changed: 96 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,36 @@ author: kgremban
77
ms.author: kgremban
88
ms.service: iot-hub
99
ms.topic: how-to
10-
ms.date: 06/10/2024
10+
ms.date: 06/12/2024
1111
---
1212

1313
# Create and manage device identities
1414

1515
Create a device identity for your device to connect to Azure IoT Hub. This article introduces key tasks for managing a device identity including registering the device, collecting its connection information, and then deleting or disabling a device at the end of its lifecycle.
1616

17+
## Prerequisites
18+
19+
* An IoT hub in your subscription. If you don't have an IoT hub, follow the steps in [Create an IoT hub](./iot-hub-create-through-portal.md)
20+
1721
## Register a device
1822

1923
In this section, you create a device identity in the [identity registry in your IoT hub](./iot-hub-devguide-identity-registry.md). A device can't connect to a hub unless it has a device identity.
2024

2125
The IoT Hub identity registry only stores device identities to enable secure access to the IoT hub. It stores device IDs and keys to use as security credentials, and an enabled/disabled flag that you can use to disable access for an individual device.
2226

23-
IoT Hub supports three methods for device authentication:
27+
When you register a device, you choose its authentication method. IoT Hub supports three methods for device authentication:
28+
29+
* **Symmetric key** - *This option is recommended for quickstart scenarios.*
30+
31+
When you register a device, you can provide keys or IoT Hub will generate keys for you. Both the device and the IoT hub have a copy of the symmetric key that can be compared when the device connects.
32+
33+
* **X.509 self-signed**
34+
35+
If your device has a self-signed X.509 certificate, then you need to give IoT Hub a version of the certificate for authentication. When you register a device, you upload a certificate *thumbprint*, which is a hash of the device's X.509 certificate. When the device connects, it presents its certificate and the IoT hub can validate it against the hash it knows. For more information, see [Authenticate identities with X.509 certificates](./authenticate-authorize-x509.md).
36+
37+
* **X.509 CA signed** - *This option is recommended for production scenarios.*
2438

25-
* **Symmetric key** - When you register a device, you can provide keys or IoT Hub will generate keys for you. Both the device and the IoT hub have a copy of the symmetric key that can be compared when the device connects.
26-
* **X.509 self-signed** - If your device has a self-signed X.509 certificate, then you need to give IoT Hub a version of the certificate for authentication. When you register a device, you upload a certificate *thumbprint*, which is a hash of the device's X.509 certificate. When the device connects, it presents its certificate and the IoT hub can validate it against the hash it knows. For more information, see [Authenticate identities with X.509 certificates](./authenticate-authorize-x509.md).
27-
* **X.509 CA signed** - If your device has a CA-signed X.509 certificate, then you can give IoT Hub a root or intermediate certificate in the signing chain for authentication. *This option is recommended for production scenarios.* Before you register a device, you upload and verify an X.509 certificate authority (CA) certificate to the IoT hub. The device has an X.509 certificate with the verified X.509 CA in its certificate chain of trust. When the device connects, it presents its full certificate chain and the IoT hub can validate it because it knows the X.509 CA. Multiple devices can authenticate against the same verified X.509 CA. For more information, see [Authenticate identities with X.509 certificates](./authenticate-authorize-x509.md).
39+
If your device has a CA-signed X.509 certificate, then you can give IoT Hub a root or intermediate certificate in the signing chain for authentication. Before you register a device, you upload and verify an X.509 certificate authority (CA) certificate to the IoT hub. The device has an X.509 certificate with the verified X.509 CA in its certificate chain of trust. When the device connects, it presents its full certificate chain and the IoT hub can validate it because it knows the X.509 CA. Multiple devices can authenticate against the same verified X.509 CA. For more information, see [Authenticate identities with X.509 certificates](./authenticate-authorize-x509.md).
2840

2941
### Prepare certificates
3042

@@ -38,18 +50,17 @@ If your device uses self-signed certificates, then you need two device certifica
3850
openssl x509 -in <certificate filename>.pem -text -fingerprint
3951
```
4052

41-
The thumbprint is included in the output of the command. For example:
42-
43-
```output
44-
SHA1 Fingerprint=D2:68:D9:04:9F:1A:4D:6A:FD:84:77:68:7B:C6:33:C0:32:37:51:12
45-
```
46-
4753
### Add a device
4854

55+
Create a device identity in your IoT hub.
56+
4957
### [Azure portal](#tab/portal)
5058

5159
1. In the [Azure portal](https://portal.azure.com), navigate to your IoT hub.
52-
1. Select **Device management** > **Devices**, then select **Add Device** to add a device in your IoT hub.
60+
61+
1. Select **Device management** > **Devices**.
62+
63+
1. Select **Add Device** to add a device in your IoT hub.
5364

5465
<!-- :::image type="content" source="./media/iot-hub-include-create-device/create-identity-portal.png" alt-text="Screen capture that shows how to create a device identity in the portal." border="true"::: -->
5566

@@ -66,26 +77,63 @@ SHA1 Fingerprint=D2:68:D9:04:9F:1A:4D:6A:FD:84:77:68:7B:C6:33:C0:32:37:51:12
6677

6778
1. Select **Save**.
6879

69-
7080
### [Azure CLI](#tab/cli)
7181

72-
### [PowerShell](#tab/powershell)
82+
Use the [az iot hub device-identity create](/cli/azure/iot/hub/device-identity#az-iot-hub-device-identity-create) command to register a device.
83+
84+
The following table describes common parameters used with this command.
85+
86+
| Parameter | Dependent parameter | Value |
87+
| -- | -- | -- |
88+
| `--device-id`, `-d` | | Provide a name for your new device. |
89+
| `--hub-name`, `-h` | | IoT hub name or hostname. |
90+
| `--auth-method`, `--am` | | Either `shared_private_key`, `x509_ca`, or `x509_thumbprint` |
91+
| | `--primary-key`, `--pk` and `--secondary-key`, `--sk` | Use with `shared_private_key` authentication if you want to provide the primary and secondary keys for your device. Omit if you want IoT Hub to generate the keys. |
92+
| | `--primary-thumbprint`, `--ptp` and `--secondary-thumbprint`, `--stp` | Use with `x509_thumbprint` authentication to provide the primary and secondary certificate thumbprints for your device. Omit if you want IoT Hub to generate a self-signed certificate and use its thumbprint. |
93+
94+
[!INCLUDE [iot-hub-pii-note-naming-device](../../includes/iot-hub-pii-note-naming-device.md)]
7395

7496
---
7597

7698
## Retrieve device connection information
7799

100+
Registered devices have multiple ways to connect to IoT Hub, depending on the SDK and authentication method. For specific information, refer to the [Azure IoT Hub device SDKs](./iot-hub-devguide-sdks.md#azure-iot-hub-device-sdks).
101+
102+
For samples and test scenarios, the most common connection method is to use a *device connection string*. A device connection string contains the name of the IoT hub, the name of the device, and the device's authentication information.
103+
104+
Device with symmetric key authentication have a connection string with the following pattern:
105+
106+
`HostName=<IOT_HUB_NAME>;DeviceId=<DEVICE_NAME>;SharedAccessKey=<PRIMARY_OR_SECONDARY_KEY>`
107+
108+
Devices with X.509 authentication, either self-signed or CA-signed, usually don't use connection strings for authentication. When they do, their connection strings take the following pattern:
109+
110+
`HostName=<IOT_HUB_NAME>;DeviceId=<DEVICE_NAME>;x509=true`
111+
112+
You can build a connection string yourself with those three pieces of connection information, or you can retrieve it with the following steps.
113+
78114
### [Azure portal](#tab/portal)
79115

80-
1. After the device is created, open the device from the list in the **Devices** pane. Copy the value of **Primary connection string**. This connection string is used by device code to communicate with the IoT hub.
116+
The Azure portal only lists connection strings for devices that use symmetric key authentication.
117+
118+
1. In the [Azure portal](https://portal.azure.com), navigate to your IoT hub.
119+
120+
1. Select **Device management** > **Devices**.
121+
122+
1. Select your device from the list in the **Devices** pane.
123+
124+
1. Copy the value of **Primary connection string**.
81125

82126
By default, the keys and connection strings are masked because they're sensitive information. If you click the eye icon, they're revealed. It's not necessary to reveal them to copy them with the copy button.
83127

84128
<!-- :::image type="content" source="./media/iot-hub-include-create-device/device-details.png" alt-text="Screen capture that shows the device connection string." border="true" lightbox="./media/iot-hub-include-create-device/device-details.png"::: -->
85129

86130
### [Azure CLI](#tab/cli)
87131

88-
### [PowerShell](#tab/powershell)
132+
Use the [az iot hub device-identity connection-string show](/cli/azure/iot/hub/device-identity#az-iot-hub-device-identity-connection-string-show) command to retrieve a device's connection string. For example:
133+
134+
```bash
135+
az iot hub device-identity connection-string show --device-id <DEVICE_NAME> --hub-name <IOT_HUB_NAME>
136+
```
89137

90138
---
91139

@@ -95,26 +143,48 @@ If you want to keep a device in your IoT hub's identity registry, but want to pr
95143

96144
### [Azure portal](#tab/portal)
97145

98-
1. In the [Azure portal](https://portal.azure.com), navigate to your IoT hub.
146+
. In the [Azure portal](https://portal.azure.com), navigate to your IoT hub.
99147

100-
1. Select **Devices** from the navigation menu.
148+
1. Select **Device management** > **Devices**.
101149

102-
1. Select the name of the device that you want to disable to view its device details page.
150+
1. Select your device from the list in the **Devices** pane.
103151

104152
1. On the device details page, set the **Enable connection to IoT Hub** parameter to **Disable**.
105153

106154
:::image type="content" source="./media/iot-hub-create-through-portal/disable-device.png" alt-text="Screenshot that shows disabling a device connection.":::
107155

108-
If you want to remove a device from your IoT hub's identity registry, you can delete its registration.
109-
110-
1. From the **Devices** page of your IoT hub, select the checkbox next to the device that you want to delete.
111-
112-
1. Select **Delete** to remove the device registration.
156+
If you want to remove a device from your IoT hub's identity registry, you can delete its registration by selecting **Delete**.
113157

114158
:::image type="content" source="./media/iot-hub-create-through-portal/delete-device.png" alt-text="Screenshot that shows deleting a device.":::
115159

116160
### [Azure CLI](#tab/cli)
117161

118-
### [PowerShell](#tab/powershell)
162+
To disable a device, use the [az iot hub device-identity update](/cli/azure/iot/hub/device-identity#az-iot-hub-device-identity-update) command and change the `status` of the device. For example:
163+
164+
```bash
165+
az iot hub device-identity update --device-id <DEVICE_NAME> --hub-name <IOT_HUB_NAME> --set status=disabled
166+
```
167+
168+
To delete a device, use the [az iot hub device-identity delete](/cli/azure/iot/hub/device-identity#az-iot-hub-device-identity-delete) command. For example:
169+
170+
```bash
171+
az iot hub device-identity delete --device-id <DEVICE_NAME> --hub-name <IOT_HUB_NAME>
172+
```
173+
174+
---
175+
176+
## Other tools for managing device identities
177+
178+
You can use other tools or interfaces to manage the IoT Hub identity registry, including:
179+
180+
* PowerShell commands
181+
182+
Refer to the [Az.IotHub](/powershell/module/az.iothub/) command set to learn how to manage device identities.
183+
184+
* Visual Studio Code
185+
186+
The [Azure IoT Hub extension for Visual Studio Code](./reference-iot-hub-extension.md) includes identity registry capabilities.
187+
188+
* REST API
119189

120-
---
190+
Refer to the [IoT Hub Service APIs](/rest/api/iothub/service/devices) to learn how to manage device identities.

0 commit comments

Comments
 (0)