我试图使用Postman调用Azure存储Blob容器而没有运气。
以下是我用于生成共享访问签名的javascript代码:
<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);
此时我从浏览器控制台获取authorizationHeader
输出并将其粘贴到Postman中。它看起来像这样:SharedKey siteassets:/4B2VjY9ZhsFxNngwhj8A9qeZC2chTQNmB1kEvyd+fM=
继承我的邮差设置:
Postman使用此输出返回403错误:
<?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>
世界上我做错了什么?