Azure IOT Provisoning服务中的个人注册无法通过REST API使用

问题描述 投票:0回答:1

我目前在使用提供的REST API的Azure设备配置服务的个人注册中面临挑战。文档中也有一些空白。

我正在按照此url中官方文档中提到的步骤进行操作:https://docs.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/ {{tenantId}} / oauth2 / token。但是实际上我们需要在此处提供SAS令牌。

[当我给AAD令牌而不是SAS令牌时,发现此错误。

{“错误代码”:401002,“ trackingId”:“ f8e3cf88-8d72-46eb-b49b-4d18630ba72b”,“ message”:“无效的授权标头。”,“ timestampUtc”:“ 2020-05-01T20:44:11.3709305Z”}

azure-iot-hub
1个回答
0
投票

经过大量阅读后,我找到了解决方案。

我们在此处尝试触发的端点属于设备置备服务。因此,当我们提供Authorization标头时,应该是所生成的SAS令牌。但是,我发现了另一个链接来创建SAS令牌,但效果不佳。 https://docs.microsoft.com/en-us/rest/api/eventhub/generate-sas-token(我遵循了类似的方法为DPS创建SAS令牌,但失败了)

我发现此命令可用于为您的DPS服务创建SAS令牌

az iot hub generate-sas-token --duration 3600 --login <primary connection string of your Device Provisoning Service.>

这将提供我们必须使用的正确的SAS令牌。提供此选项后,注册即可顺利创建

© www.soinside.com 2019 - 2024. All rights reserved.