i'm incorporating facebook authentication in app using passport node , express, , mysql db (using bookshelf.js orm). when go log in using facebook, after entering facebook credentials, error 'cannot /auth/facebook/callback?code= {callback_code}'. i've tried following solutions found on stackoverflow: 1, 2, 3, 4
and outside post: 5
none of these have worked.
in fb app account, i've set 'valid oauth redirect uris' inside of client oauth settings 'localhost:8080/auth/facebook/callback', app domain 'localhost', , site url 'localhost:8080/'.
below code. appreciated!
routes:
module.exports = function (apirouter, passport) { apirouter.get('/events', isloggedin, eventcontroller.getallevents); apirouter.post('/events', eventcontroller.addevent); apirouter.get('/auth/facebook', passport.authenticate('facebook', {scope : ['email ', 'public_profile', 'user_friends']})); apirouter.get('/auth/facebook/callback', passport.authenticate('facebook', {failureredirect: '/'})) };
passport config:
passport.use(new facebookstrategy({ clientid : configauth.facebookauth.clientid, clientsecret : configauth.facebookauth.clientsecret, callbackurl : 'http://localhost:8080/auth/facebook/callback' }, function(token, refreshtoken, profile, done) { console.log('looking user fb'); process.nexttick(function() { console.log('looking user fb inside async'); new user({ 'facebook_id' : profile.id }) .fetch() .then(function(usermodel) { if (usermodel) { return usermodel; } else { new user({ facebook_token: token, first_name: profile.name.givenname, last_name: profile.name.familyname }).save() .then(function(model) { console.log('new user saved', model); done(null, model); },function(error) { console.log('error saving new user: ', error); done(error); }); } done(null, usermodel); }, function(error) { console.log('error: ', error); done(error); }); }); }));
Comments
Post a Comment