Я пытаюсь сделать запрос GET, чтобы получить сведения об учетной записи моей учетной записи хранилища BLOB-объектов Azure, но каждый раз он показывает, что проверка подлинности завершилась неудачно. Может ли кто-нибудь сказать, правильно ли сформирован заголовок или строка подписи или есть какие-то другие проблемы?
Вот код:
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 - Status 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, заголовках и Auth можно найти здесь: 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
РЕДАКТИРОВАТЬ: Параметр строки =
был исправлен на :