How to generate SharedKeyLite for Azure Table Storage REST request(如何为 Azure 表存储 REST 请求生成 SharedKeyLite)
问题描述
我正在尝试使用 Postman 调用 Azure 表存储,但不断收到:
I'm trying to call Azure Table Storage using Postman but keep getting :
服务器未能验证请求.确保值包括签名在内的授权标头格式正确.
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
我在 Postman 中用于 pre-call 脚本的代码如下:
The code I am using for the pre-call script in Postman is as follows:
var storageAccount = "**mystorageaccount**";
var accountKey = "**mystoragekey**";
var date = new Date();
var UTCstring = date.toUTCString();
var data = date + "
" + "/**mystorageaccount**/**mytable**"
var encodedData = unescape(encodeURIComponent(data));
var hash = CryptoJS.HmacSHA256(encodedData, accountKey);
var signature = hash.toString(CryptoJS.enc.Base64);
var auth = "SharedKeyLite " + storageAccount + ":" + signature;
postman.setEnvironmentVariable("auth", auth);
postman.setEnvironmentVariable("date", UTCstring);
Postman中的headers如下:
The headers in Postman are as follows:
Authorization : {{auth}}
date : {{date}}
version : 2015-12-11
我猜这个问题可能出在数据变量上,但没有什么想法.
I am guessing the issue may be with the data variable, but running out of ideas.
推荐答案
您收到此错误的原因是您没有将帐户密钥转换为缓冲区.请更改以下代码行:
The reason you're getting this error is because you're not converting your account key to a buffer. Please change the following line of code:
var hash = CryptoJS.HmacSHA256(encodedData, accountKey);
到
var hash = CryptoJS.HmacSHA256(encodedData, Buffer.from(accountKey, 'base64'));
你不应该得到错误.
更新
我也遇到了同样的错误.请尝试以下代码:
I also got the same error. Please try the following code:
var storageAccount = "**mystorageaccount**";
var accountKey = "**mystoragekey**";
var date = new Date();
var UTCstring = date.toUTCString();
var data = UTCstring + "
" + "/**mystorageaccount**/**mytable**"
var encodedData = unescape(encodeURIComponent(data));
var hash = CryptoJS.HmacSHA256(encodedData, CryptoJS.enc.Base64.parse(accountKey));
var signature = hash.toString(CryptoJS.enc.Base64);
var auth = "SharedKeyLite " + storageAccount + ":" + signature;
postman.setEnvironmentVariable("auth", auth);
postman.setEnvironmentVariable("date", UTCstring);
我刚刚尝试了上面的代码,并且能够在我的表中列出实体.
I just tried the code above and was able to list entities in my table.
这篇关于如何为 Azure 表存储 REST 请求生成 SharedKeyLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何为 Azure 表存储 REST 请求生成 SharedKeyLite


基础教程推荐
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01