Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add underlying http request agent configuration support to oauth2 #330

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ exports.OAuth2.prototype._request= function(method, url, headers, post_body, acc


var realHeaders= {};
for( var key in this._customHeaders ) {
realHeaders[key]= this._customHeaders[key];
for (var key in this._customHeaders) {
if (key != "agentAddOptions") {
realHeaders[key] = this._customHeaders[key];
}
}
if( headers ) {
for(var key in headers) {
Expand Down Expand Up @@ -117,6 +119,12 @@ exports.OAuth2.prototype._request= function(method, url, headers, post_body, acc
headers: realHeaders
};

if (this._customHeaders.agentAddOptions) {
for (var key in this._customHeaders.agentAddOptions) {
options[key] = this._customHeaders.agentAddOptions[key];
}
}

this._executeRequest( http_library, options, post_body, callback );
}

Expand Down Expand Up @@ -225,4 +233,4 @@ exports.OAuth2.prototype.get= function(url, access_token, callback) {
headers= {};
}
this._request("GET", url, headers, "", access_token, callback );
}
}
13 changes: 13 additions & 0 deletions tests/oauth2tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,5 +300,18 @@ vows.describe('OAuth2').addBatch({
}, {}, null, function() {});
}
}
},
'When the user passes in the agent options in customHeaders': {
topic: new OAuth2("clientId", "clientSecret", undefined, undefined, undefined,
{ 'agentAddOptions' : { 'rejectUnauthorized': false } }),
'When calling get': {
'we should see the agent options mixed into options property passed to http-library' : function(oa) {
oa._executeRequest= function( http_library, options, callback ) {
assert.equal(options["rejectUnauthorized"], false);
assert.equal(options.headers["rejectUnauthorized"], undefined);
};
oa.get("", {});
}
}
}
}).export(module);