Azure上载blob 403

时间:2015-10-19 13:57:53

标签: angularjs azure blob azure-storage-blobs

我尝试在我的 Azure containers

上传文件

这是我通过 ajax 发送的请求之一:

headers: Object
Authorization: "SharedKey MYACCOUNT:ENC_KEY"
Content-Type: "application/octet-stream"
data: File
x-ms-blob-type: "BlockBlob"
x-ms-date: "Mon, 19 Oct 2015 13:54:53 GMT"
x-ms-version: "2009-09-19"
type: "PUT"
url: "https://MYACCOUNT.blob.core.windows.net/data-test"

对于 ENC_KEY 我使用:

authorizationHeader =
  compute: (options, xhrOptions) ->
  sig = @_computeSignature(options, xhrOptions)
  result = 'SharedKey ' + options.storageAccount + ':' + sig
  result

_computeSignature: (options, xhrOptions) ->
          sigString = @_getSignatureString(options, xhrOptions)
          key = CryptoJS.enc.Base64.parse(options.primaryKey)
          hmac = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key)
          hmac.update sigString
          hash = hmac.finalize()
          result = hash.toString(CryptoJS.enc.Base64)
          result

任何想法?

编辑: authorizationHeader的所有代码 - > https://gist.github.com/F4Ke/88debcede3b7e2312b11

2)

错误回应:

PUT https://MYACCOUNT.blob.core.windows.net/data-test 403 (Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.)

3)

#_getCanonicalizedHeadersString
itemcreation.coffee:232 x-ms-blob-type:BlockBlob
x-ms-date:Mon, 19 Oct 2015 14:33:15 GMT
x-ms-version:2009-09-19

#_getSignatureString
PUT




application/octet-stream






x-ms-blob-type:BlockBlob
x-ms-date:Mon, 19 Oct 2015 14:35:19 GMT
x-ms-version:2009-09-19
/MYACCOUNT/MYACCOUNT.blob.core.windows.net/data-test

1 个答案:

答案 0 :(得分:0)

可以找到描述如何签名消息的REST文档here。您还可以查看节点共享密钥实现hhere - 也可以帮助您...