So I am trying to add facebook authentication to my ionic2 app using express and passportjs. I almost got it working except the last part of redirecting the user back to ionic2 app after authorization. my both the apps are working on different ports; ionic2 running on http://localhost:8100 and express app for backend stuff running on http://localhost:8000 .
These are the steps I followed:
-
Created app on developers.facebook.com and got the App ID and secret ID.
-
Under Products>Facebook>settings, I have added callBack url as
-
Then in my express app which is running on localhost:8000, I have added facebook authentication strategy as shown in https://github.com/jaredhanson/passport-facebook which is something like this:
passport.use(new FacebookStrategy({ clientID: FACEBOOK_APP_ID, clientSecret: FACEBOOK_APP_SECRET, callbackURL: "http://localhost:8000/auth/facebook/callback" }, function(accessToken, refreshToken, profile, cb) { User.findOrCreate({ facebookId: profile.id }, function (err, user) { return cb(err, user); }); } )); app.get('/auth/facebook', passport.authenticate('facebook')); app.get('/auth/facebook/callback', passport.authenticate('facebook', { failureRedirect: '/login' }), function(req, res) { // Successful authentication, redirect home. res.redirect('/'); //how to redirect back to ionic app instead of / });
so now whenever user clicks on facebook button on ionic2 app its going to facebook authentication page and once successfully authenticated it’s redirecting back to localhost:8000/auth/facebook/callback as expected but I want to redirect back to ionic app. how can I solve this problem? Need some guidance to solve this.