bettiolo / oauth-signature-js

JavaScript OAuth 1.0a signature generator (RFC 5849) for node and the browser
https://www.npmjs.com/package/oauth-signature
BSD 3-Clause "New" or "Revised" License
232 stars 72 forks source link

Add partial support for falsy parameters #9

Closed jmendiara closed 6 years ago

jmendiara commented 10 years ago

Cause falsy permissive comparisons, all falsy values are considered '' when computing the signature

var parameters = { 
 a: '',
 b: null,
 c: undefined,
 d: false,
 e: 0,
 f: [],
 g: true,
 h: 1
};
//...
var signature = oauthSignature.generate(httpMethod, url, parameters, consumerSecret, tokenSecret);

//URL used for signature
//a=&b=&c=&d=&e=&f=&g=true&h=1

This PR solves the false and 0 use case, following the same approach used for true and Number, creating an URL

//a=&b=&c=&d=false&e=0&f=&g=true&h=1
jmendiara commented 10 years ago

Sorry, I have no time for making test

bettiolo commented 10 years ago

Hi @jmendiara, The comment I wrote for the issue #10 answers this as well: https://github.com/bettiolo/oauth-signature-js/issues/10#issuecomment-56973402

Please, tell me if this clarifies the situation.

jmendiara commented 10 years ago

This is a matter of parameter serialization, not RFC stuff. If I want to send GET http://foo.com/bar?from=0&to=1&oauthStuff

I would need to encode the parameters this way

var params = {
   from: '0',
   to: 1
};
oauthSignature.generate(..., params, ....);

otherwise, the server signature will fail cause of you signed the url GET http://foo.com/bar?from=&to=1&oauthStuff