我目前面临着使用提供的 REST API 在 Azure 设备配置服务中进行个人注册的挑战。文档中也存在一些空白。
我正在按照此网址中的官方文档中提到的步骤进行操作:https://learn.microsoft.com/en-us/rest/api/iot-dps/createorupdateindividualenrollment/createorupdateindividualenrollment https://learn.microsoft.com/en-us/rest/api/iot-dps/createorupdateindividualenrollment/createorupdateindividualenrollment
通过免费试用订阅,我创建了物联网中心、设备配置服务并将两者链接起来。截至目前,我正在尝试创建注册组。 REST API 的详细信息如下。
**Request:**
POST /enrollments?api-version=2019-03-31 HTTP/1.1
Host: <my dps Service endpoint name>
Authorization: SAS Token generated from az cli
Content-Type: application/json
Content-Type: text/plain
{"mode":"create",
"enrollments": [
{
"attestation": {
"type":"symmetricKey"
},
"registrationId": "test1",
"deviceId":"durg0235"
}]
}
**Response:**
Http Status: 401 Unauthorized
{
"errorCode": 401002,
"trackingId": "252fe53f-6c9c-4893-9fc8-500a1965802c",
"message": "Unauthorized",
"timestampUtc": "2020-05-01T20:38:28.0522219Z"
}
请让我知道我在这里做错了什么。
注意:文档中存在空白。在文档中,提到会有 Authorization 标头,并且提到我们必须通过调用此 url 来获取令牌:https://login.microsoftonline.com/ https://login.microsoftonline.com/{{tenantId}}/oauth2/token。但实际上我们需要在这里提供 SAS 令牌。
当我提供 AAD 令牌而不是 SAS 令牌时,我发现了此错误。
{
“错误代码”:401002,
"trackingId": "f8e3cf88-8d72-46eb-b49b-4d18630ba72b",
"message": "无效的授权标头。",
“timestampUtc”:“2020-05-01T20:44:11.3709305Z”
}