How to call Azure Blob Storage using REST API with SAS

1.7k Views Asked by At

I am attempting to call a Azure Storage Blob container using Postman with no luck.

Here is my javascript code for generating the 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 the string that will need signed with my 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 the Authorization Header for the request and print to console
var authorizationHeader = String.format("SharedKey {0}:{1}", accountName,
            signature);

console.log(authorizationHeader);

At this point I grab that authorizationHeaderoutput from the browser console and paste it in Postman. It looks something like this: SharedKey siteassets:/4B2VjY9ZhsFxNngwhj8A9qeZC2chTQNmB1kEvyd+fM=

Heres my Postman settings: enter image description here

Postman returns a 403 error with this output:

<?xml version="1.0" encoding="utf-8"?>
<Error>
    <Code>AuthenticationFailed</Code>
    <Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:ed8376ec-0001-0055-54ed-a97527000000
Time:2015-06-18T17:40:05.3456247Z</Message>
    <AuthenticationErrorDetail>The MAC signature found in the HTTP request '/4B2VjY9ZhsFxNngwhj8A9qeZC2chTQNmB1kEvyd+fM=' is not the same as any computed signature. Server used following string to 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 the world am I doing wrong?

0

There are 0 best solutions below