Authorization of Azure Storage service REST API

后端 未结 1 763
别那么骄傲
别那么骄傲 2020-12-11 13:44

I\'ve been stuck for the whole day making my first call of Azure Storage REST API. Postman\'s response showed that it\'s due to error in Azure authentication, but I have no

相关标签:
1条回答
  • 2020-12-11 14:34

    Chrome Developer Tool just returned No 'Access-Control-Allow-Origin' header

    As you are using javascript to send http requests against to Azure Storage Server directly from client. It's a common CORS issue.

    When you occur this issue, you can enable the CORS for your storage services. For simple, you can leverage Microsoft Azure Storage Explorer to configure your storage.

    AuthenticationFailed

    I did two modifications based on your code snippet, in my test project to make it work.

    1. var hash = CryptoJS.HmacSHA256(strToSign, key); The second parameter, should be a base64 decode from the account key, refer to the Azure Storage SDK for node.js
    2. In my test, I had to use SharedKey scheme and authenticate with SharedKey token to make your scenario to work.

    Here is my test code snippet, FYI.,

    var key = "key-copied-from-azure-storage-account";
    var strTime = (new Date()).toUTCString();
    var strToSign = 'GET\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:' + strTime + '\nx-ms-version:2015-12-11\n/<accountname>/\ncomp:list';
    var secret = CryptoJS.enc.Base64.parse(key);
    var hash = CryptoJS.HmacSHA256(strToSign, secret);
    var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
    var auth = "SharedKey <accountname>:"+hashInBase64; 
    

    Additionally, for security reason, please implement the Azure Storage Services in backend web server. As using pure javascript on client, will expose your account name and account key to public, which will raise the risk to your data and info.

    0 讨论(0)
提交回复
热议问题