私はAzure Storage REST APIの最初の呼び出しを一日中続けてきました。郵便配達員の返答は、それがAzure認証のエラーによるものであることを示しましたが、何が問題なのか分かりません。ここでAzureストレージサービスREST APIの承認
AzureストレージのREST APIを送信するために、ブラウザのスクリプトです:
function azureListContainers() {
var key = "key-copied-from-azure-storage-account";
var strTime = (new Date()).toUTCString();
var strToSign = 'GET\n\n\n\nx-ms-date:' + strTime + '\nx-ms-version:2015-12-11\n/myaccount/?comp=list';
var hash = CryptoJS.HmacSHA256(strToSign, key);
var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
var auth = "SharedKeyLite myaccount:"+hashInBase64;
console.log(strToSign);
console.log(auth);
console.log(strTime);
$.ajax({
type: "GET",
beforeSend: function (request)
{
request.setRequestHeader("Authorization", auth);
request.setRequestHeader("x-ms-date", strTime);
request.setRequestHeader("x-ms-version", "2015-12-11");
},
url: "https://myaccount.blob.core.windows.net/?comp=list",
processData: false,
success: function(msg) {
console.log(msg);
}
});
}
クローム開発者用ツールは、単にさらなる理由なしいいえ「アクセス制御 - 許可 - 起源」ヘッダを返されたので、私はvar auth
の内容をコピーしそしてvar strTime
は、ポストマンのツールを使用して同じ要求を作成した:
[Command]
GET https://myaccount.blob.core.windows.net/?comp=list
[Headers]
Authorization:SharedKeyLite myaccount:Z9/kY/D+osJHHz3is+8yJRqhj09VUlr5n+PlePUa8Lk=
x-ms-date:Tue, 09 Aug 2016 10:30:49 GMT
x-ms-version:2015-12-11
[Response Body]
<?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:9be3d595-0001-0012-4929-f2fde2000000
Time:2016-08-09T10:31:52.6542965Z</Message>
<AuthenticationErrorDetail>The MAC signature found in the HTTP request 'Z9/kY/D+osJHHz3is+8yJRqhj09VUlr5n+PlePUa8Lk=' is not the same as any computed signature. Server used following string to sign: 'GET
x-ms-date:Tue, 09 Aug 2016 10:30:49 GMT
x-ms-version:2015-12-11
/myaccount/?comp=list'.</AuthenticationErrorDetail>
</Error>
を2つの文字列をdiffをした後、私は私のスクリプトでvar strToSign
は、Azureのを署名するために使用される文字列と同じであると考えています。しかし、まだ認証エラーがありました。何が問題なのかを教えてください。
私の人生を保存していただきありがとうございます、ゲーリー! noobとして、[this Authentication doc](https://msdn.microsoft.com/en-us/library/azure/dd179428.aspx)から直接アクセスしましたが、まずbase64のデコードが必要であるかどうかはわかりませんでした。可能であれば、他の人がクイックスタートできるようにサンプルコードスニペットをドキュメントに追加してください。 :-) – Ernie
ところで、SharedKeyLiteでも動作します! – Ernie
それを聞いてうれしいです。 –