Passport-facebook:'无法获取/ auth / facebook / callback?code = {callback_code}

时间:2016-01-24 17:23:35

标签: node.js authentication express passport.js passport-facebook

我正在使用Passport with Node和Express以及MySQL db(使用Bookshelf.js ORM)在我的应用中加入Facebook身份验证。当我使用Facebook登录时,在输入我的Facebook凭据后,我收到错误'无法获取/ auth / facebook / callback?code = {callback_code}'。我尝试过在stackoverflow上找到的以下解决方案:1234

这个外部帖子:5

这些都没有奏效。

在我的FB应用帐户中,我将客户端OAuth设置中的“有效OAuth重定向URI”设置为“localhost:8080 / auth / facebook / callback”,将App Domain设置为“localhost”,将“站点URL”设置为“localhost” :8080 /'.

以下是我的代码。非常感谢任何帮助!

路线:

    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.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 for user from fb');
  process.nextTick(function() {
    console.log('looking for user from 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);
       });
   });
}));

0 个答案:

没有答案