我已经部署了我的wordpress网站,并且在OAuth身份验证的第一步涉及创建签名时遇到问题(目前,我对nonce和timestamp进行了硬编码,并将基本字符串和使用者密钥复制并粘贴到在线HMAC中-SHA1编码器(https://www.freeformatter.com/hmac-generator.html#ad-output)来创建签名。
以下是我的代码:
const url = 'http://auth-test-site.azurewebsites.net/oauth1/request';
const base_string = 'POST&http%3A%2F%2Fauth-test-site.azurewebsites.net%2Foauth1%2Frequest&oauth_consumer_key%3DieQCM48wXWuW%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D123456789%26oauth_nonce%3Dnonce%26oauth_version%3D1.0';
console.log(url);
fetch(url, {
method: "POST",
headers: {
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "OAuth oauth_consumer_key=ieQCM48wXWuW,oauth_signature_method=HMAC-SHA1,oauth_timestamp=123456789,oauth_nonce=FFeySWNH1Am,oauth_version=1.0,oauth_signature=5c6f358b1086cf2387e46a6c00e412fcfc2a4743",
},
credentials: "same-origin"
}).then(function(response) {
console.log(response.text());
return response.text();
}, function(error) {
console.error(error.message) //=> String
});
这是打印到控制台的内容:
06:44:31: http://auth-test-site.azurewebsites.net/oauth1/request
06:44:32: Promise {
06:44:32: "_40": 0,
06:44:32: "_55": "
06:44:32: Consumer Key is invalid",
06:44:32: "_65": 1,
06:44:32: "_72": null,
06:44:32: }
对于测试用户,消费者密钥是ieQCM48wXWuW,消费者密钥是9Yf0HG8RWrk0a4IKxwnkK2LUvd15NNF0b98jZwpOmQhoO7vv。 有没有人指出为什么请求不起作用?谢谢!
编辑:我删除了三条斜线并取得了进展,但现在我明白了:07:01:01: Promise {
07:01:01: "_40": 0,
07:01:01: "_55": "
07:01:01: OAuth signature does not match",
07:01:01: "_65": 1,
07:01:01: "_72": null,
07:01:01: }
关于如何获得正确的OAuth签名的任何想法?