我正在尝试根据可用的文档将标准网关角色分配给网关设备 https://docs.internetofthings.ibmcloud.com/apis/swagger/v0002-beta/security-gateway-beta.html#!/Limited_Gateway/put_authorization_devices_deviceId_roles
但我继续获得403 Forbidden错误。我正在使用应用程序凭据(api密钥和令牌),它具有"操作应用程序"角色以及分配角色的特权。
这里有几个运行的脚本,我用虚拟值替换了org,type,id和token
curl -X PUT \
https://dummyorg.internetofthings.ibmcloud.com:443/api/v0002/authorization/devices/g%3Adummyorg%3Adummytype%3Adummyid/roles \
-H 'authorization: Basic dummyauth' \
-H 'content-type: application/json' \
-d '{
"roles": [
{
"roleId": "PD_STANDARD_GW_DEVICE",
"roleStatus": 1
}
]
}'
响应 HTTP 403禁止
当我尝试获得设备的角色时,它可以正常工作
curl -X GET \
https://dummyorg.internetofthings.ibmcloud.com:443/api/v0002/authorization/devices/g%3Adummyorg%3Adummytype%3Adummyid/roles \
-H 'authorization: Basic dummyauth' \
响应
{
"results": [
{
"roleId": "PD_PRIVILEGED_GW_DEVICE",
"roleStatus": 1
}
],
"rolesToGroups": {}
}
答案 0 :(得分:0)
注意网址 - 你必须使用'g',你必须对其进行编码。您需要包含一个具有API密钥的基本授权标头(我的标准应用程序):
PUT /api/v0002/authorization/devices/g%3AOrgID%3Agatewaytype%3AmyGateway/roles HTTP/1.1
Host: OrgID.internetofthings.ibmcloud.com
Authorization: Basic removed
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: removed
{
"roles": [
{
"roleId": "PD_STANDARD_GW_DEVICE",
"roleStatus": 1
}
],
"rolesToGroups": {}
}