Skip to content

Instantly share code, notes, and snippets.

@sirkirby
Created January 24, 2017 19:33
Show Gist options
  • Save sirkirby/29189f33968e3d7dfc3f025d801816b5 to your computer and use it in GitHub Desktop.
Save sirkirby/29189f33968e3d7dfc3f025d801816b5 to your computer and use it in GitHub Desktop.
Azure Storage API Authorization Shared Key generation - Runscope
// requires CryptoJS and Moment javascript libraries
// set the initial variables on your test
var storageAccount = variables.get("accountName");
var accountKey = variables.get("accountKey");
var date = moment().format("ddd, DD MMM YYYY HH:mm:ss");
var data = date + "\n" +
"/" + storageAccount + " /Tables"
// utf-8 encoding
var encodedData = unescape(encodeURIComponent(data));
// encrypt and encode the data
var hash = CryptoJS.HmacSHA256(encodedData, variables.get("accountKey"));
var signature = hash.toString(CryptoJS.enc.Base64);
// build the auth header
var auth = "SharedKeyLite " + variables.get("accountName") + ":" + signature;
// add the headers to the request
request.headers["Authorization"] = auth;
request.headers["Date"] = date;
console.log(JSON.stringify(request));
@lintao47
Copy link

1105acd0-0e64-40d8-ab22-927fcba32527

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment