Some minor reformatting and 'standardisation' of the merged code

Also updating package.json to reflect Echo support
This commit is contained in:
ciaranj
2011-05-10 23:21:49 +01:00
parent c1c9270181
commit 37c2408187
3 changed files with 24 additions and 23 deletions

View File

@ -6,8 +6,8 @@ var crypto= require('crypto'),
querystring= require('querystring');
exports.OAuth= function(requestUrl, accessUrl, consumerKey, consumerSecret, version, authorize_callback, signatureMethod, nonceSize, customHeaders) {
this._echo = false;
this._isEcho = false;
this._requestUrl= requestUrl;
this._accessUrl= accessUrl;
this._consumerKey= consumerKey;
@ -30,14 +30,14 @@ exports.OAuth= function(requestUrl, accessUrl, consumerKey, consumerSecret, vers
};
exports.OAuthEcho= function(realm, verify_credentials, consumerKey, consumerSecret, version, signatureMethod, nonceSize, customHeaders) {
this._echo = true;
this._isEcho = true;
this._realm= realm;
this._verifyCredentials = verify_credentials;
this._consumerKey= consumerKey;
this._consumerSecret= this._encodeData( consumerSecret );
this._version= version;
if( signatureMethod != "PLAINTEXT" && signatureMethod != "HMAC-SHA1")
throw new Error("Un-supported signature method: " + signatureMethod );
this._signatureMethod= signatureMethod;
@ -107,10 +107,10 @@ exports.OAuth.prototype._isParameterNameAnOAuthParameter= function(parameter) {
// build the OAuth request authorization header
exports.OAuth.prototype._buildAuthorizationHeaders= function(orderedParameters) {
var authHeader="OAuth ";
if (this._echo) {
if( this._isEcho ) {
authHeader += 'realm="' + this._realm + '",';
}
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.
@ -200,7 +200,7 @@ exports.OAuth.prototype._createSignature= function(signatureBase, tokenSecret) {
hash= sha1.HMACSHA1(key, signatureBase);
}
}
return hash;
return hash;
}
exports.OAuth.prototype.NONCE_CHARS= ['a','b','c','d','e','f','g','h','i','j','k','l','m','n',
'o','p','q','r','s','t','u','v','w','x','y','z','A','B',
@ -250,16 +250,19 @@ exports.OAuth.prototype._prepareParameters= function( oauth_token, oauth_token_s
if( oauth_token ) {
oauthParameters["oauth_token"]= oauth_token;
}
var sig;
if (!this._echo) {
if( this._isEcho ) {
sig = this._getSignature( "GET", this._verifyCredentials, this._normaliseRequestParams(oauthParameters), oauth_token_secret);
}
else {
if( extra_params ) {
for( var key in extra_params ) {
oauthParameters[key]= extra_params[key];
}
}
var parsedUrl= URL.parse( url, false );
if( parsedUrl.query ) {
var key2;
var extraParameters= querystring.parse(parsedUrl.query);
@ -275,10 +278,8 @@ exports.OAuth.prototype._prepareParameters= function( oauth_token, oauth_token_s
}
}
}
sig = this._getSignature( method, url, this._normaliseRequestParams(oauthParameters), oauth_token_secret);
} else {
sig = this._getSignature( "GET", this._verifyCredentials, this._normaliseRequestParams(oauthParameters), oauth_token_secret);
}
var orderedParameters= this._sortRequestParams( this._makeArrayOfArgumentsHash(oauthParameters) );
@ -298,12 +299,13 @@ exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_toke
var headers= {};
var authorization = this._buildAuthorizationHeaders(orderedParameters);
if (this._echo) {
if ( this._isEcho ) {
headers["X-Verify-Credentials-Authorization"]= authorization;
} else {
}
else {
headers["Authorization"]= authorization;
}
headers["Host"] = parsedUrl.host
for( var key in this._headers ) {