我在开发一个Node.js应用程序..。尝试从JWPlatform API请求数据,并且很难创建auth签名。也许我说的完全错了,但我已经联系了JWPlatform开发团队,他们说他们对Node或JS还不太熟悉,不能指出我做错了什么……他们提供了PHP和Python,我已经看过了,但是仍然不知道我的错误在哪里。
为了在这里让事情变得更简单,我已经硬编码了变量,我只是想输出一个相同的SHA-1十六进制摘要,就像在他们的有记录的例子中找到的一样,它包含在这个帖子的底部。
文档化示例:fbdee51a45980f9876834dc5ee1ec5e93f67cb89
当前输出:f067ff121b5a4388fecc00f01dabeddd02d707f4
好吧,所以。我觉得这信息够多了。
这是我的密码
var crypto = require("crypto");
test = {
apiFormat: 'xml',
apiKey: 'XOqEAfxj',
apiNonce: 80684843,
apiTimestamp: 1237387851,
apiText: ('démo').toString("utf8"),
apiSecret: 'uA96CFtJa138E2T5GhKfngml'
}
// Concatinate string
concat = "api_format=" + test.apiFormat +
"&api_key=" + test.apiKey +
"&api_nonce=" + test.apiNonce +
"&api_timestamp=" + test.apiTimestamp +
"&text=" + encodeURI(test.apiText);
// Create Hash
testSignature = crypto.createHmac("sha1", concat+
test.apiSecret).digest("hex");
console.log(testSignature);
// Outputs: 'f067ff121b5a4388fecc00f01dabeddd02d707f4'
// Expecting: 'fbdee51a45980f9876834dc5ee1ec5e93f67cb89'他们的文档
1:所有文本参数转换为UTF-8编码。
text: démo
api_format: xml
api_key: XOqEAfxj
api_nonce: 80684843
api_timestamp: 12373878512:所有文本参数URL编码(参见OAuth核心1.0第5.1节)。
text: d%C3%A9mo
api_format: xml
api_key: XOqEAfxj
api_nonce: 80684843
api_timestamp: 12373878513:参数是根据它们的编码名称排序的(参见OAuth Core1.0 9.1.1节)。排序顺序是字典字节值排序。
api_format: xml
api_key: XOqEAfxj
api_nonce: 80684843
api_timestamp: 1237387851
text: d%C3%A9mo4:参数被连接到一个字符串中。每个参数的名称与对应的值用‘=’字符分隔(即使值为空),而每个名称-值对由‘&’字符分隔(请参见OAuth核心1.0 9.1.1节)。
api_format=xml&api_key=XOqEAfxj&api_nonce=80684843&api_timestamp=1237387851&text=d%C3%A9mo5:增加秘密,计算SHA-1摘要.秘密被添加到SBS的末尾:
api_format=xml&api_key=XOqEAfxj&api_nonce=80684843&api_timestamp=1237387851&text=d%C3%A9mouA96CFtJa138E2T5GhKfngml6:为上述字符串计算的SHA-1 HEX摘要如下:
fbdee51a45980f9876834dc5ee1ec5e93f67cb89经过验证的API调用如下所示:
http://api.jwplatform.com/v1/videos/list?text=d%C3%A9mo&api_nonce=80684843&api_timestamp=1237387851&api_format=xml&api_signature=fbdee51a45980f9876834dc5ee1ec5e93f67cb89&api_key=XOqEAfxj发布于 2014-03-05 04:18:33
我相信你真的还好到了哈希阶段。您正在尝试使用HMAC函数,但我认为它们只是在使用哈希。试试这个:
testSignature = crypto.createHash('sha1').update(concat + test.apiSecret).digest('hex');这应该会让你得到十六进制字符串fbdee51a45980f9876834dc5ee1ec5e93f67cb89。
https://stackoverflow.com/questions/22187779
复制相似问题