1

我创建了一个 facebook 应用程序,只有我自己使用。现在我已经上线了,但除了我之外没有人能够登录。

他们得到以下错误。

FacebookTokenError: This authorization code has been used.
 at Strategy.parseErrorResponse (/var/www/html/project/node_modules/passport-facebook/lib/strategy.js:199:12)
 at Strategy.OAuth2Strategy._createOAuthError (/var/www/html/project/node_modules/passport-facebook/node_modules/passport-oauth2/lib/strategy.js:345:16)
 at /var/www/html/project/node_modules/passport-facebook/node_modules/passport-oauth2/lib/strategy.js:171:43
 at /var/www/html/project/node_modules/passport-facebook/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:177:18
 at passBackControl (/var/www/html/project/node_modules/passport-facebook/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:123:9)
 at IncomingMessage.<anonymous> (/var/www/html/project/node_modules/passport-facebook/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:143:7)
 at IncomingMessage.EventEmitter.emit (events.js:117:20)
 at _stream_readable.js:920:16
 at process._tickCallback (node.js:415:13)

这里可能是什么问题。应用程序已上线。

4

4 回答 4

1

您需要在 FacebookStrategy 回调中调用 done()。为了测试你可以做

function(accessToken, refreshToken, profile, done) {
console.log("Auth done");
done(null, profile);
}

你可以在这里参考:https ://github.com/jaredhanson/passport/issues/108

于 2015-10-23T13:22:01.170 回答
1

我在 Express 中有一个 REST api,它使用来自 Jeroen Pelgrims 的信息使用无会话 Facebook 登录。它的作用是:

使用 Facebook 策略登录 将令牌和信息保存在用户数据库中 使用该令牌进行承载登录 护照 Facebook 身份验证在回调页面中使用的内容是:passport.authenticate('strategy', options, user, error)

该行为正确地引发了该错误!正如@jsilveira 在评论中所说,如果用户登录两次,则会发生错误......

我的答案很简单,我发现了错误......继续阅读有一个但是......

// facebook 认证和登录的路由

 router.get('/auth/facebook',
        passport.authenticate('facebook', {session: false, scope : ['email'] })
    );

// handle the callback after facebook has authenticated the user
router.get('/auth/facebook/callback',
    passport.authenticate('facebook',  { session: false, failureRedirect : '/'}),

    // on succes
    function(req,res) {
        // return the token or you would wish otherwise give eg. a succes message
        res.render('json', {data: JSON.stringify(req.user.access_token)});
    },

    // on error; likely to be something FacebookTokenError token invalid or already used token,
    // these errors occur when the user logs in twice with the same token
    function(err,req,res,next) {
        // You could put your own behavior in here, fx: you could force auth again...
        // res.redirect('/auth/facebook/');
        if(err) {
            res.status(400);
            res.render('error', {message: err.message});
        }
    }
);

但是,如果你们希望它再次登录/授权,您可以在错误部分插入回调或重定向。

希望这可以澄清你们遇到的一些问题。如果您有任何问题或要求,请不要害羞。信息在我的个人资料上。

PS:stackoverflow.com 有一个重新验证的答案,如下所示:

app.post('/login', function(req, res, next) {
  passport.authenticate('local', function(err, user, info) {
      if (err) {
      return next(err); // will generate a 500 error
      }
      // Generate a JSON response reflecting authentication status
      if (! user) {
      return res.send({ success : false, message : 'authentication failed' });
  }
  return res.send({ success : true, message : 'authentication succeeded' });
  })(req, res, next);
});
于 2015-10-23T12:07:58.970 回答
0

我偶然发现了这个线程:https ://github.com/jaredhanson/passport-facebook/issues/93

普遍的共识似乎是jdomingo 的解决方案是为人们工作的。enableProof他的解决方案包括在战略中启用:

passport.use(new FacebookStrategy({
clientID: ---,
clientSecret: ---,
callbackURL: "http://---/auth/facebook/callback",
enableProof: true
}

jdomingo进一步解释了为什么这会有所帮助。FWIW,我自己并没有真正尝试过。

于 2015-10-20T16:44:36.387 回答
0

看起来你不是唯一一个:

这里

他们提供了几种解决方案。

无论如何 - 如果你真的想要一个解决方案,你将不得不在这里粘贴你的代码。

于 2015-10-20T16:44:39.063 回答