node-oauth icon indicating copy to clipboard operation
node-oauth copied to clipboard

Does not allow for multiple querystring parameters with the same name

Open deremer opened this issue 13 years ago • 1 comments

Some APIs that use this module allow the developer to pass the same querystring parameter multiple times. For instance, see SimpleGeo and categories... https://simplegeo.com/docs/api-endpoints/simplegeo-places

The oauth implementation turns querystring parameters into object, so a given parameter can only exist one time, so it changes the parameter name to be category[0], categort[1], etc.

I devised a way to fix this by modifying "exports.OAuth.prototype._normaliseRequestParams" to look like this...

exports.OAuth.prototype._normaliseRequestParams= function(arguments) { var argument_pairs= this._makeArrayOfArgumentsHash(arguments);

// David DeRemer: added logic to allow for multiple occurrences of the same querystring parameter for (var i=0; i<argument_pairs.length; i++) { if (argument_pairs[i][0].search(/[\d_]/) != -1) { argument_pairs[i] = [argument_pairs[i][0].replace(/[\d_]/,''), argument_pairs[i][1]]; } }

// First encode them #3.4.1.3.2 .1 for(var i=0;i<argument_pairs.length;i++) { argument_pairs[i][0]= this._encodeData( argument_pairs[i][0] ); argument_pairs[i][1]= this._encodeData( argument_pairs[i][1] ); }

// Then sort them #3.4.1.3.2 .2 argument_pairs= this._sortRequestParams( argument_pairs );

// Then concatenate together #3.4.1.3.2 .3 & .4 var args= ""; for(var i=0;i<argument_pairs.length;i++) { args+= argument_pairs[i][0]; args+= "=" args+= argument_pairs[i][1]; if( i < argument_pairs.length-1 ) args+= "&"; }
return args; }

You may want to consider adding something like this into the main branch.

deremer avatar Sep 29 '11 19:09 deremer

👍

tchap avatar Apr 22 '16 14:04 tchap