gpt4 book ai didi

javascript - 对 AZURE STORAGE BLOB 中的 GET 容器详细信息进行 REST API 调用时身份验证失败

转载 作者:行者123 更新时间:2023-12-03 02:27:22 24 4
gpt4 key购买 nike

我正在尝试获取 Azure 存储 Blob 中的容器详细信息。但它抛出 Auth Failed,我认为我的资源字符串表述可能存在问题。代码如下:

const CryptoJS = require("crypto-js");
const request = require("request");
const parser = require("xml2json");

require("dotenv").config();

const account = process.env.ACCOUNT_NAME || "";
const key = process.env.ACCOUNT_KEY || "";

var strTime = new Date().toUTCString();
var strToSign =
"GET\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:" +
strTime +
`\nx-ms-version:2018-03-28\n/${account}/demo?restype:container`;
var secret = CryptoJS.enc.Base64.parse(key);
var hash = CryptoJS.HmacSHA256(strToSign, secret);
var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
var auth = `SharedKey ${account}:${hashInBase64}`;

const options = {
url: `https://${account}.blob.core.windows.net/demo?restype=container`,

headers: {
Authorization: auth,
"x-ms-date": strTime,
"x-ms-version": "2018-03-28",
},
};

function callback(error, response, body) {
console.log(error);
console.log(response.headers["Last-Modified"]);
console.log(response);
}

request(options, callback);

在上面的示例中,demo 是我帐户中的私有(private)容器。

最佳答案

请尝试更改以下代码行:

var strToSign =
"GET\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:" +
strTime +
`\nx-ms-version:2018-03-28\n/${account}/demo?restype:container`;

var strToSign =
"GET\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:" +
strTime +
`\nx-ms-version:2018-03-28\n/${account}/demo\nrestype:container`;

关于javascript - 对 AZURE STORAGE BLOB 中的 GET 容器详细信息进行 REST API 调用时身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66437018/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com