Add support for specifying whatever static HTTP headers one wishes with the OAuth requests

This commit is contained in:
ciaranj 2010-08-14 19:21:12 +01:00
parent 752c4419f9
commit 24c91e02b9

View File

@ -4,7 +4,7 @@ var crypto= require('crypto'),
URL= require('url'), URL= require('url'),
querystring= require('querystring'); querystring= require('querystring');
exports.OAuth= function(requestUrl, accessUrl, consumerKey, consumerSecret, version, authorize_callback, signatureMethod, nonceSize) { exports.OAuth= function(requestUrl, accessUrl, consumerKey, consumerSecret, version, authorize_callback, signatureMethod, nonceSize, customHeaders) {
this._requestUrl= requestUrl; this._requestUrl= requestUrl;
this._accessUrl= accessUrl; this._accessUrl= accessUrl;
this._consumerKey= consumerKey; this._consumerKey= consumerKey;
@ -21,6 +21,9 @@ exports.OAuth= function(requestUrl, accessUrl, consumerKey, consumerSecret, vers
throw new Error("Un-supported signature method: " + signatureMethod ) throw new Error("Un-supported signature method: " + signatureMethod )
this._signatureMethod= signatureMethod; this._signatureMethod= signatureMethod;
this._nonceSize= nonceSize || 32; this._nonceSize= nonceSize || 32;
this._headers= customHeaders || {"Accept" : "*/*",
"Connection" : "close",
"User-Agent" : "Node authentication"}
}; };
exports.OAuth.prototype._getTimestamp= function() { exports.OAuth.prototype._getTimestamp= function() {
@ -207,9 +210,11 @@ exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_toke
headers["Authorization"]= authHeader; headers["Authorization"]= authHeader;
headers["Host"] = parsedUrl.host headers["Host"] = parsedUrl.host
headers["Accept"]= "*/*"
headers["Connection"]= "close" for( var key in this._headers ) {
headers["User-Agent"]= "Express authentication" headers[key]= this._headers[key];
}
headers["Content-length"]= post_body ? post_body.length : 0; //Probably going to fail if not posting ascii headers["Content-length"]= post_body ? post_body.length : 0; //Probably going to fail if not posting ascii
headers["Content-Type"]= post_content_type; headers["Content-Type"]= post_content_type;