使用Azure设备配置服务的其余API删除设备?

时间:2020-10-07 05:15:14

标签: azure azure-iot-hub

使用设备供应服务在azure IoT中心删除已注册的设备所需的URL格式是什么...

我读了这篇文章,但是却抛出了404

https://docs.microsoft.com/en-us/rest/api/iot-dps/deletedeviceregistrationstate/deletedeviceregistrationstate

在请求标头中,我添加了If-Match标签,但我是否需要添加带有SaS令牌的授权标签,如果需要,SaS令牌将是我用于使用Device Provisioning Service注册设备的令牌

1 个答案:

答案 0 :(得分:0)

如果我需要SaS令牌,它将是我用于注册的令牌 设备使用设备预配服务

要生成access_token(将在请求的Authorization标头中使用),需要遵循一些步骤。

先决条件:

以下是步骤:

使用Azure CLI登录

az login

设置活动订阅

az account set --subscription "your subscription name or id"

创建服务主体

az ad sp create-for-rbac -n "your service principal name. Can be like 'jongpostman7'"

上面命令的输出将类似于下面的图像。 enter image description here

将此输出复制到临时位置,一分钟之内将需要这些值。

现在应邮递员的要求。您需要先致电AAD Token request,其回复将为您提供access_token。您可以在DPS删除设备请求中使用此访问令牌。 AAD请求将如下所示:-

POST https://login.microsoftonline.com/{{tenantId}}/oauth2/token 请参阅下面的图像以获取请求正文。

enter image description here

grant_typeclient_credentials client_id是以上命令输出中收到的appId client_secret是以上命令输出中收到的password tenant_id是以上命令输出中收到的tenant resourcehttps://management.azure.com/

以上请求的响应如下:- enter image description here

现在,您拥有可以在DPS删除设备REST API中使用的access_token。 Authorization标头如下:

AuthorizationBearer <access_token_received_above>

参考链接here