azure - 使用设备客户端和使用 HTTP DELETE 的设备预配服务在 azure iot hub 中删除(取消预配)设备
问题描述
尝试使用 DPS 从 azure IoT 中心删除设备时导致未授权问题的原因:
在 azure iot hub 中使用 DPS 进行删除操作的文档
我尝试了取消配置设备,但也收到错误 401 或 405。授权标头中使用的 sas 令牌的格式是什么:
生成 sas 令牌的代码:
public String buildSasToken1(String deviceId) throws SecurityProviderException {
String keyValue = Utils.getKeyValue(deviceId, iotConfig.getSymmetricKey());
Long expiry = getExpiry(iotConfig.getExpiry());
try {
String dpsUrl=iotConfig.getHubUrl1();
String targetUri = URLEncoder.encode(dpsUrl.toLowerCase(), StandardCharsets.UTF_8.name());
String toSign = targetUri + "\n" + expiry;
byte[] keyBytes = Base64.decodeBase64Local(keyValue.getBytes("UTF-8"));
SecretKeySpec signingKey = new SecretKeySpec(keyBytes, "HmacSHA256");
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(signingKey);
byte[] rawHmac = mac.doFinal(toSign.getBytes("UTF-8"));
String signature = URLEncoder.encode(Base64.encodeBase64StringLocal(rawHmac), "UTF-8");
String token = String.format(iotConfig.getTokenFormat(), targetUri, signature, expiry)+"&skn=provisioningserviceowner";
log.info("TOKEN "+token);
return token;
} catch (Exception e) {
log.info(e.getMessage());
throw new RuntimeException(e);
}
}
我附上了在 PostMan 中显示请求的图片:
解决方案
推荐阅读
- java - 有关 OpenJDK 11 和 OpenJFX 11(和 Proguard)的迁移问题
- ios - 从 Swift 4 中的 UICollectionView 获取单元格图像
- angular - 如何在没有来自 forRoot() jnitalization 的默认 AppState 的组件中提供 Store
- python - ttk.Treeview - 如何在不先点击的情况下更改选择
- spring-boot - Keycloak Spring Boot 令牌未从 Zuul 代理传播到 Spring Boot 服务
- python - 将 Pandas 和 Win32com 用于 Excel 宏
- java - 其中 R 在 AppCompatActivity 中声明
- api - 专业版支持的 SOAP 标头中的 API 令牌
- javascript - 基于 JSON 的数据表条件渲染行
- onelogin - Onelogin CLI 身份验证失败