diff --git a/lib/oauth.js b/lib/oauth.js index 671462f..66a21b8 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -70,6 +70,20 @@ exports.OAuth.prototype._normalizeUrl= function(url) { return parsedUrl.protocol + "//" + parsedUrl.hostname + port + parsedUrl.pathname; } +// build the OAuth request authorization header +exports.OAuth.prototype._buildAuthorizationHeaders= function(orderedParameters) { + var authHeader="OAuth "; + for( var i= 0 ; i < orderedParameters.length; i++) { + // Whilst the all the parameters should be included within the signature, only the oauth_ arguments + // should appear within the authorization header. + if( orderedParameters[i][0].match('^oauth_') == "oauth_") { + authHeader+= this._encodeData(orderedParameters[i][0])+"=\""+ this._encodeData(orderedParameters[i][1])+"\","; + } + } + authHeader= authHeader.substring(0, authHeader.length-1); + return authHeader; +} + // Takes a literal in, then returns a sorted array exports.OAuth.prototype._sortRequestParams= function(argumentsHash) { var argument_pairs= []; @@ -196,19 +210,7 @@ exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_toke } var headers= {}; - - // build request authorization header - var authHeader="OAuth "; - for( var i= 0 ; i < orderedParameters.length; i++) { - // Whilst the all the parameters should be included within the signature, only the oauth_ arguments - // should appear within the authorization header. - if( orderedParameters[i][0].match('^oauth_') == "oauth_") { - authHeader+= this._encodeData(orderedParameters[i][0])+"=\""+ this._encodeData(orderedParameters[i][1])+"\","; - } - } - authHeader= authHeader.substring(0, authHeader.length-1); - - headers["Authorization"]= authHeader; + headers["Authorization"]= this._buildAuthorizationHeaders(orderedParameters); headers["Host"] = parsedUrl.host for( var key in this._headers ) {