javascript - How to call Azure Blob Storage using REST API with SAS -
i attempting call azure storage blob container using postman no luck.
here javascript code generating shared access signature:
<script src="https://github.com/dmester/sffjs/blob/master/src/stringformat.js"></script> <script src="https://github.com/caligatio/jssha/blob/master/src/sha256.js"></script> var method = "get"; //build date in utc var dateinrfc1123format = new date(); dateinrfc1123format = dateinrfc1123format.toutcstring(); console.log(dateinrfc1123format); //azure blob account info var accountname = "siteassets"; var containername = "test"; var key = "supersecretomitted"; //required stuff var canonicalizedheaders = string.format("x-ms-date:{0}\nx-ms-version: 2009-09-19\n", dateinrfc1123format); var canonicalizedresource = string.format("/{0}/{1}/", accountname, containername); // building string need signed key var stringtosign = string.format("{0}\n\n\n\n\n\n\n\n\n\n\n\n{1}{2}", method, canonicalizedheaders, canonicalizedresource); console.log("stringtosign: " + stringtosign); //create base64 sha256 hash var shaobj = new jssha("sha-256", "text"); shaobj.sethmackey(key, "text"); shaobj.update(stringtosign); var hmac = shaobj.gethmac("b64"); var signature = hmac; //build authorization header request , print console var authorizationheader = string.format("sharedkey {0}:{1}", accountname, signature); console.log(authorizationheader);
at point grab authorizationheader
output browser console , paste in postman. looks this: sharedkey siteassets:/4b2vjy9zhsfxnngwhj8a9qezc2chtqnmb1kevyd+fm=
heres postman settings:
postman returns 403 error output:
<?xml version="1.0" encoding="utf-8"?> <error> <code>authenticationfailed</code> <message>server failed authenticate request. make sure value of authorization header formed correctly including signature. requestid:ed8376ec-0001-0055-54ed-a97527000000 time:2015-06-18t17:40:05.3456247z</message> <authenticationerrordetail>the mac signature found in http request '/4b2vjy9zhsfxnngwhj8a9qezc2chtqnmb1kevyd+fm=' not same computed signature. server used following string sign: 'get x-ms-date:thu, 18 jun 2015 17:39:45 gmt x-ms-version:2009-09-19 /siteassets/test comp:list restype:container'.</authenticationerrordetail> </error>
what in world doing wrong?
Comments
Post a Comment