passport-oauth2 icon indicating copy to clipboard operation
passport-oauth2 copied to clipboard

How to set proxy in passport-oauth2

Open byteshiva opened this issue 9 years ago • 1 comments

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

byteshiva avatar Jul 13 '16 08:07 byteshiva

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);

iwaiktos avatar Feb 13 '17 06:02 iwaiktos