My app uses Passport with two Strategies: Facebook and Local. Is it possible to determine somehow (some property or state variable) which Strategy the user used to log in to the app (i.e., determine from some information within Passport)? Is there some property or other setting in maybe the req object that indicates the provider associated with the logged-in user? Would really prefer to get this from Passport rather than setting up my ow variables to keep track of this, if at all possible.

有帮助吗?

解决方案

That's not provided in Passport directly. I've done something similar in an app, and just use an extra bit of middleware on the login route to track session-related information, such as what provider was used. It looks something like:

app.get('/auth/facebook/callback',
  passport.authenticate('facebook', { failureRedirect: '/login' }),
  function(req, res, next) {
    req.session.loggedInWith = 'facebook';
    next();
  },
  function(req, res) {
    // Successful authentication, redirect home.
    res.redirect('/');
  });
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top