passport-oauth2
passport-oauth2 copied to clipboard
How to set proxy in passport-oauth2
I see there is one option to set proxy. Is it possible to do the follwing in passport-oauth2
Steps
I would like to add httpsProxyAgent to node-auth. Does the current implementation has option to add agent option to node-oauth.
This is what I would need...
var HttpsProxyAgent = require('https-proxy-agent'); if (process.env['https_proxy']) { httpsProxyAgent = new HttpsProxyAgent(process.env['https_proxy']); }
Finally, set the httpsProxyAgent to the request options right before _executeRequest gets called like this:
options.agent = httpsProxyAgent
One of my ugly workaround solution:
var strategy = new OAuth2Strategy({
authorizationURL: 'https://www.example.com/oauth2/authorize',
tokenURL: 'https://www.example.com/oauth2/token',
clientID: EXAMPLE_CLIENT_ID,
clientSecret: EXAMPLE_CLIENT_SECRET,
callbackURL: "http://localhost:3000/auth/example/callback"
}, function(accessToken, refreshToken, profile, cb) {
User.findOrCreate({ exampleId: profile.id }, function (err, user) {
return cb(err, user);
});
});
var HttpsProxyAgent = require('https-proxy-agent');
if (process.env['https_proxy']) {
var httpsProxyAgent = new HttpsProxyAgent(process.env['https_proxy']);
strategy._oauth2.setAgent(httpsProxyAgent);
}
passport.use(strategy);