使用设备客户端和设备预配置服务使用HTTP DELETE在Azureure IoT中心中删除取消配置设备

问题描述

什么原因导致尝试使用DPS从azure IoT中心删除设备时导致未授权的问题:

Documentation

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中显示请求的图片:

enter image description here

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...