UPDATED: current solution below.
I am adding facebook login to my site - that I was hoping to be simple but difficult.
(built with Node.js / Express API and Angular)
So, my questions I ask to help with:
1 - Instead of successRedirect returns a token
I use passport-facebookto help with the login process, but in the callback, instead of successRedirect, I can simply say that it returns json containing the token. Note that the token is a JWT that I already use with standard email authentication, and am currently creating it in passport.serializeUser:
passport.serializeUser(function(user, done) {
var token =
done(null, user);
});
And then in the callback do something like:
router.get('/login/facebook/callback',
passport.authenticate('facebook', {
res.json({success: true, token:token)
})
);
2 - How to handle the client side
, , - , "" $http.get. URL-, , "login with facebook", router.get('/login/facebook', facebook, , , , , .
, - Angular, , , , , .
(, , - )
, , , :
1 - API-. URL-, JWT:
router.get('/login/facebook/callback',
passport.authenticate('facebook',
{ session: false, failureRedirect: "/processfblogin/false" }),
function(req, res) {
res.redirect("/api/processfblogin/" + req.user._id);
}
);
URL.
, . $http, CORs 302. URL :
res.redirect('http://localhost:3000/#/fbToProcess/' + token);
, , .
json, , : -)