问题描述
什么原因导致尝试使用DPS从azure IoT中心删除设备时导致未授权的问题:
Documentation for delete operation using DPS in azure iot hub
我尝试取消配置设备,但也收到错误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中显示请求的图片:
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)