diff --git a/lib/oauth.js b/lib/oauth.js index d0313e7..c7acfff 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -42,7 +42,7 @@ exports.merge = function(a,b) { if (!b || !(b instanceof Object)) { return a; } - + var keys = Object.keys(b); for (var key in keys) { @@ -68,11 +68,11 @@ exports.normalize = function(obj) if (obj[prop].constructor === Array) { obj[prop] = obj[prop].sort(); for(var child in obj[prop]) { - prop[child] = oauth.normalize(child); + prop[child] = exports.normalize(child); } } else if (obj[prop] instanceof Object) { - obj[prop] = oauth.normalize(obj[prop]); + obj[prop] = exports.normalize(obj[prop]); } } return obj; @@ -96,7 +96,7 @@ exports.normalizeURL = function(path) { slashes: true }; - if ((p.port == 80 && p.protocol == 'http:') || + if ((p.port == 80 && p.protocol == 'http:') || (p.port == 443 && p.protocol == 'https:')) { delete ret.port; } @@ -127,7 +127,7 @@ exports.request = function(options, callback) { } var uri = exports.fillURL(options.path, options.host, options.port, options.https); - options.headers = signRequest(options.method, uri, options.headers, + options.headers = signRequest(options.method, uri, options.headers, options.body, options.oauth_signature, options.realm); var req; @@ -136,15 +136,15 @@ exports.request = function(options, callback) { } else { req = http.request(options, callback); } - + req.write = function(chunk, normalize) { if (normalize || options.body) { chunk = normalizeBody(chunk); } - + return http.ClientRequest.prototype.write.call(this, chunk, 'utf-8'); }; - + req.end(); return req; }; @@ -192,7 +192,7 @@ function signRequest(method, path, headers, body, signature, realm) { else { throw new TypeError("Invalid signature type"); } - + var esc = querystring.escape; querystring.escape = _encodeURI; auth.realm = realm; @@ -203,7 +203,7 @@ function signRequest(method, path, headers, body, signature, realm) { return headers; } -exports.signRequest = signRequest; +exports.signRequest = signRequest; function nonce() { return uuid(); @@ -312,13 +312,13 @@ Signature.prototype.sign = function() { Signature.prototype.baseString = function(method, url, params) { querystring.escape = _encodeURI; - + var baseString = [ method.toUpperCase(), _encodeURI(exports.normalizeURL(url)), _encodeURI(querystring.stringify(exports.normalize(params))) ].join('&'); - + return baseString; };