How To Correctly Sign An Http Request To Twitter's Rest Api V1.1 In Nodejs?
I'm only getting error 32 'Could not authenticate you' when I call twitter.request() (defined in my cloud/twitter.js file) inside Parse Cloud Code. I've done everything Twitter tol
Solution 1:
It turned out to be an easy fix (thankfully). The problem lied in a &
trailing my signature (facepalm). Here's the function I had to change.
function getAuthSignature (user, request, oauth) {
var signingKey, body, signatureBase;
signingKey =
ENCODING_METHOD(CONSUMER_SECRET) + '&' + ENCODING_METHOD(TOKEN_SECRET);
body =
mapObject(oauth, ampersandEncoding)
.concat(mapObject(request.params, ampersandEncoding))
.sort();
// Remove trailing ampersand. (aka the fix)
body.push(body.pop().replace('&', ''));
signatureBase =
request.method.toUpperCase() + '&' +
ENCODING_METHOD(request.url) + '&' +
ENCODING_METHOD(body.join(''));
return crypto.createHmac('sha1', signingKey)
.update(signatureBase)
.digest('base64');
};
Post a Comment for "How To Correctly Sign An Http Request To Twitter's Rest Api V1.1 In Nodejs?"