jaredhanson / passport-google

Google (OpenID) authentication strategy for Passport and Node.js.
MIT License
149 stars 80 forks source link

Access req.session before passport.use #34

Open hariawan opened 9 years ago

hariawan commented 9 years ago

Scenario: I have 2 kind of login systems

  1. Google - for Analytics
  2. Google - for Youtube

And I have 2 config

  1. for Analytics
  2. for Youtube
youtube: {
  clientID          : 'xxx.apps.googleusercontent.companyname',
  clientSecret      : 'xxx-xxxxxxx',
  callbackURL       : '/auth/youtube/callback',
  passReqToCallback : true
},
analytics: {
  clientID          : 'yyy.apps.googleusercontent.com',
  clientSecret      : 'yyy-yyyyy',
  callbackURL       : '/auth/analytics/callback',
  passReqToCallback : true
 },

My passport.js

passport.use(new GoogleStrategy(**config.blabla**, function(req, accessToken, refreshToken, profile, done) {
  blablabla
}

I want my config.blabla to be flexible.


My current idea

I send req.session to this

.get('/auth/analytics',
  function(req, res, next) {
    req.session.authAnalytics = true;
    next();
  },
  passport.authenticate('google', { scope: ['profile', 'email', 'https://www.googleapis.com/auth/analytics'] }))

But we can't call req.session.authAnalytics in passport.js I want to change config.blablabla to config.analytics if req.session.authAnalytics is not undefined.

Any idea?