I'm using PassportJS in an ExpressJS web app.
In app.js:
//passportjs google
passport.use(new GoogleStrategy({
clientID: '...',
clientSecret: '...',
callbackURL: '...'
}, user.oauth2Login
));
app.get('/auth/google',
passport.authenticate('google', { scope: 'email' }));
app.get('/auth/google/callback',
passport.authenticate('google', { successReturnToOrRedirect: '/home', failureRedirect: '/login' }))
In my user modulue:
exports.oauth2Login = function(accessToken, refreshToken, profile, done) {
//get ip here
}
How can I get the IP of the user in oauth2Login?
Use the passReqToCallback options. Details can be found here:
http://passportjs.org/guide/authorize/
(It's a non-obvious location for this documentation, I know.)