Azure Storage REST API에 대한 첫 번째 호출을 하루 종일 계속했습니다. 우편 배달부의 답변에 따르면 Azure 인증의 오류로 인한 것이지만 문제가 무엇인지 전혀 알지 못합니다. 여기 Azure 스토리지 서비스 REST API 인증
는 푸른 저장 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);
}
});
}
단지 반환
Chrome 개발자 도구 없음 '액세스 제어는-원점 허용'더 이유없이 헤더, 그래서 나는 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>
두 문자열을 diff를 후를, 내 스크립트에 var strToSign
믿지는 푸른 서명하는 데 사용되는 문자열과 동일합니다. 하지만 여전히 인증 오류가있었습니다. 문제가 무엇인지 알려주십시오.
내 생명을 구 해주셔서 감사합니다, 게리! 멍청한 놈으로 [이 인증 문서] (https://msdn.microsoft.com/en-us/library/azure/dd179428.aspx)에서 직접 온 것은 기본 64 디코드가 필요하다는 것을 몰랐습니다. 가능한 경우 다른 사람들이 빠른 시작을 위해 샘플 코드 스 니펫을 문서에 추가하십시오. :-) – Ernie
또한 SharedKeyLite도 작동합니다! – Ernie
그 이야기를 듣고 기쁩니다. –