Connect Local Users to Facebook/Twitter with PassortJS

I have an existing user base, that I want to allow them to link with their Facebook/Twitter Accounts. Looks like I can use passportjs but am having difficulty,

Right now, a url pass in their user/pass, I do a local stragety, and look up the user. Then I want to perform an authorize I presume. I get the facebook promopts asking if I want to allow, and I hit the callback with the accessToken, but I have no way to tie that token to an existing user in my db as I see now way to get the request info.

passport.serializeUser(function(user, done) {
  done(null, user);
});

passport.deserializeUser(function(user, done) {
    Users.findOne({_id: user._id}, function(err, user) {
        return done(err, user);
    });
});

passport.use(new LocalStrategy({ passReqToCallback: true }, function(req, username, password, done) {
        Users.findOne({_id: username}, function(err, user) {
            return done(null, user);
        });
    }
));


passport.use(new FacebookStrategy({
    clientID: 'xxxx',
    clientSecret: 'xxxx',
    callbackURL: "http://xxxx/facebook/callback",
    passReqToCallback: true
  },
  function(req, accessToken, refreshToken, profile, done) {

    //  How would I get access to the user found in the LocalStrategy here so I can associate the accessToken to the user in the db?
    console.log(accessToken);
    console.log(refreshToken);

    var err = null;
    var user = {};
    return done(err, user);

  }
));

server.get('/facebook', passport.authenticate('local', { failureRedirect: '/login', failureFlash: true }),
    function (req, res) {
        if (req && req.user) {
            passport.authorize('facebook', { scope: ['publish_actions','manage_pages'] })(req, res);
        }
});

server.get('/facebook/callback',
  passport.authorize('facebook', { failureRedirect: '/facebook/failure', successRedirect: '/facebook/success' }),
  function(req, res) {
    res.redirect('/');
  }
);

Assuming that the user is already logged in with the local strategy, the user should be available on the request as req.user. You can then add the facebook credential information to the existing user object.

Check to see which URL you are redirecting to on your Facebook callback and make sure that you aren't generating different sessions between the time that you log in locally and the time that you are directed to your callback from Facebook.

I had a similar issue that was driving me crazy, and it's because my redirects were different.

For example, I was navigating to http://localhost:3000 in Chrome, logging in and req.user was being set correctly. On my Facebook dev settings, and Passport config, I was redirecting to http://hostname.local:3000/auth/facebook.

As long as your local login and redirect share the same session, then req.user should be available.