I am trying to make a GET request to get Account details of my Azure Blob Storage account, but it shows Auth failed each and every time. Can anyone tell whether the Header or Signature String formed is correct or is there any other issue?
Here's the code:
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);
After this, the response.statusCode which I am getting is Status 403.
statusCode: 403,
statusMessage: 'Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.',
The details about the azure-blob and headers and Auth could be found here: 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
EDIT:
The string param =
has been corrected to :