Skip to content
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
7 changes: 7 additions & 0 deletions lib/oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ exports.OAuth2.prototype._request= function(method, url, headers, post_body, acc
headers: realHeaders
};

var proxyServer = process.env['https_proxy'] || process.env['HTTPS_PROXY'];
if (proxyServer) {
var HttpsProxyAgent = require('https-proxy-agent');
var httpsProxyAgent = new HttpsProxyAgent(proxyServer);
options.agent = httpsProxyAgent;
}

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

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
, "main" : "index.js"
, "author" : "Ciaran Jessup <[email protected]>"
, "repository" : { "type":"git", "url":"http://github.com/ciaranj/node-oauth.git" }
, "dependencies": {
"https-proxy-agent": "^1.0.0"
}
, "devDependencies": {
"vows": "0.5.x"
}
Expand Down
14 changes: 14 additions & 0 deletions tests/oauth2tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,5 +286,19 @@ vows.describe('OAuth2').addBatch({
oa.get("", {});
}
}
},
'When the user has an https_proxy environment variable set': {
topic: new OAuth2("clientId", "clientSecret", undefined, undefined, undefined,
undefined),
'When calling get': {
'we should see the http proxy agent in options passed to http-library' : function(oa) {
process.env.https_proxy = "http://proxy-server";
oa._executeRequest= function( http_library, options, callback ) {
assert.isNotNull(options.agent);
};
oa.get("", {});
delete process.env.https_proxy;
}
}
}
}).export(module);