【发布时间】:2021-05-31 17:55:24
【问题描述】:
我正在尝试发出 GET 请求以获取我的 Azure Blob 存储帐户的帐户详细信息,但它每次都显示 Auth 失败。 任何人都可以判断形成的 Header 或 Signature String 是否正确或是否有任何其他问题?
代码如下:
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}/\ncomp:properties\nrestype:account`;
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/?comp=properties&restype=account`,
headers: {
Authorization: auth,
"x-ms-date": strTime,
"x-ms-version": "2018-03-28",
},
};
function callback(error, response, body) {
var json = parser.toJson(body);
console.log(error);
console.log(response);
if (!error && response.statusCode == 200) {
var json = parser.toJson(body);
console.log(json);
}
}
request(options, callback);
在此之后,我得到的 response.statusCode 是状态 403。
statusCode: 403,
statusMessage: 'Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.',
可以在此处找到有关 azure-blob 和标头以及身份验证的详细信息: https://docs.microsoft.com/en-us/rest/api/storageservices/authorize-with-shared-key
https://docs.microsoft.com/en-us/rest/api/storageservices/get-account-information
编辑:
字符串参数= 已更正为:
【问题讨论】:
标签: javascript node.js azure azure-blob-storage azure-authentication