Adding ability to specify an agent for OAuth2 requests
This commit is contained in:
parent
ec6a1b2eaf
commit
6baf574f87
|
@ -15,7 +15,16 @@ exports.OAuth2= function(clientId, clientSecret, baseSite, authorizePath, access
|
|||
this._authMethod= "Bearer";
|
||||
this._customHeaders = customHeaders || {};
|
||||
this._useAuthorizationHeaderForGET= false;
|
||||
}
|
||||
|
||||
//our agent
|
||||
this._agent = undefined;
|
||||
};
|
||||
|
||||
// Allows you to set an agent to use instead of the default HTTP or
|
||||
// HTTPS agents. Useful when dealing with your own certificates.
|
||||
exports.OAuth2.prototype.setAgent = function(agent) {
|
||||
this._agent = agent;
|
||||
};
|
||||
|
||||
// This 'hack' method is required for sites that don't use
|
||||
// 'access_token' as the name of the access token (for requests).
|
||||
|
@ -129,6 +138,11 @@ exports.OAuth2.prototype._executeRequest= function( http_library, options, post_
|
|||
|
||||
var result= "";
|
||||
|
||||
//set the agent on the request options
|
||||
if (this._agent) {
|
||||
options.agent = this._agent;
|
||||
}
|
||||
|
||||
var request = http_library.request(options);
|
||||
request.on('response', function (response) {
|
||||
response.on("data", function (chunk) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{ "name" : "oauth"
|
||||
, "description" : "Library for interacting with OAuth 1.0, 1.0A, 2 and Echo. Provides simplified client access and allows for construction of more complex apis and OAuth providers."
|
||||
, "version" : "0.9.14"
|
||||
, "version" : "0.9.15"
|
||||
, "directories" : { "lib" : "./lib" }
|
||||
, "main" : "index.js"
|
||||
, "author" : "Ciaran Jessup <ciaranj@gmail.com>"
|
||||
|
|
|
@ -286,5 +286,19 @@ vows.describe('OAuth2').addBatch({
|
|||
oa.get("", {});
|
||||
}
|
||||
}
|
||||
},
|
||||
'When specifying an agent, that agent is passed to the HTTP request method' : {
|
||||
topic : new OAuth2('clientId', 'clientSecret', undefined, undefined, undefined, undefined),
|
||||
'When calling _executeRequest': {
|
||||
'we whould see the agent being put into the options' : function(oa) {
|
||||
oa.setAgent('awesome agent');
|
||||
oa._executeRequest({
|
||||
request : function(options, cb) {
|
||||
assert.equal(options.agent, 'awesome agent');
|
||||
return new DummyRequest(new DummyResponse(200));
|
||||
}
|
||||
}, {}, null, function() {});
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
|
|
Loading…
Reference in New Issue