使用passport-facebook-token验证facebook令牌时出错

时间:2016-06-18 14:29:37

标签: javascript node.js facebook-graph-api passport-facebook

我在使用passport-facebook-token库时遇到问题。我的节点app.js看起来像:

var passport = require('passport');
var FacebookTokenStrategy = require('passport-facebook-token');

app.use(passport.initialize());
app.use(passport.session());

passport.use(new FacebookTokenStrategy({
        clientID: "myclientid",
        clientSecret: "myclientsecret"
    },
    function(accessToken, refreshToken, profile, done) {
      logger.info(JSON.stringify(accessToken));
      logger.info(JSON.stringify(refreshToken));
      logger.info(JSON.stringify(profile));
      logger.info(JSON.stringify(done));

      return done(null, user);
    }
));

并打印:

info: "EAAH7GGhOLX4BAFY1cUQuTEUUtdAZAgAZAQr3S..."
info: undefined
info: {"provider":"facebook","id":"10153779813157657","displayName":"..."}}
info: undefined

在我的auth.route.js中:

var passport = require('passport');
//var strategy = require('passport-facebook-token');

router.post('/fabookauth', passport.authenticate('facebook-token'), function(req, res) {

    // never called because the error occur into passport.authenticate

  logger.info(JSON.stringify(req.body));
  res.json({
    email: req.body.email
  });
});

当我调用此端点时,控制台上会打印一个未定义的错误。

查看passport-facebook-token源代码,我想我发现了问题:

https://github.com/drudge/passport-facebook-token/blob/master/src/index.js

_createClass(FacebookTokenStrategy, [{
    key: 'authenticate',
    value: function authenticate(req, options) {
      var _this2 = this;

      var accessToken = this.lookup(req, this._accessTokenField);
      var refreshToken = this.lookup(req, this._refreshTokenField);

      if (!accessToken) return this.fail({ message: 'You should provide ' + this._accessTokenField });

      this._loadUserProfile(accessToken, function (error, profile) {
        if (error) return _this2.error(error);

        var verified = function verified(error, user, info) {
          if (error) return _this2.error(error);
          if (!user) return _this2.fail(info);

          return _this2.success(user, info);
        };

        if (_this2._passReqToCallback) {
          _this2._verify(req, accessToken, refreshToken, profile, verified);
        } else {
          _this2._verify(accessToken, refreshToken, profile, verified);
        }
      });
    }
}

验证的功能始终未定义。

我看了很多例子来做这项工作,但我无法弄清楚问题,我做错了什么?这是库错误吗?

0 个答案:

没有答案