Gentle refactor to improve testability of the authorization headers code
This commit is contained in:
parent
29b5abd1f8
commit
8a4b7e6b94
28
lib/oauth.js
28
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 ) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user