Reputation: 45
I'm rewriting an authentication system to be OAuth only with Passport JS. I've designed a user flow as described below, but I can't see where the best point to get Passport to interact with information from the original request is.
The flow will be:
I'm looking to get access to the req.params inside of the Google Strategy, because this is the point I would typically create a new profile, and company for first time users. But if there's an invitation code, I want to do lookups on that info at this point.
I can't see any documentation that supports this approach, other than Node Passport invitation strategy which uses a password after initial sign up.
Can you get access to req object inside the strategy or is there a better way to approach this with another middleware?
Upvotes: 2
Views: 971
Reputation: 3297
I think what you're looking for is passReqToCallback
Example from docs:
passport.use(new TwitterStrategy({
consumerKey: TWITTER_CONSUMER_KEY,
consumerSecret: TWITTER_CONSUMER_SECRET,
callbackURL: "http://www.example.com/auth/twitter/callback",
passReqToCallback: true
},
function(req, token, tokenSecret, profile, done) {
if (!req.user) {
// Not logged-in. Authenticate based on Twitter account.
} else {
// Logged in. Associate Twitter account with user. Preserve the login
// state by supplying the existing user after association.
// return done(null, req.user);
}
}
));
See passReqToCallback
in the docs: http://passportjs.org/docs/authorize
Upvotes: 1