本文介绍了护照回调身份验证不通过REQ和RES的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此身份验证工作正常,我也得到一个重定向:

this authenticate works fine and I get a redirect:

server.post(authPostRoute, passport.authenticate(
    'local'
    , { successRedirect: '/', failureRedirect: '/login' }
));     

该身份验证挂回调后调用:

this authenticate hangs after the call back is called:

server.post(authPostRoute, passport.authenticate(
    'local'
    , function(){ console.log('Hitting the callback'); console.log(arguments)}
));     

这会将下面的一段:

this logs the following piece:

{ '0': null,
  '1':
   { id: [Getter/Setter],
     firstName: [Getter/Setter],
     lastName: [Getter/Setter],
     email: [Getter/Setter],
     addedOn: [Getter/Setter],
     active: [Getter/Setter],
     password: [Getter/Setter] },
  '2': undefined }

但整个文档()它看起来好像shuold传递R​​EQ和资源,但它显然不是。然后,code调用回调:

But throughout the documentation (http://passportjs.org/guide/authenticate/) it looks as though it shuold be passed req and res, but it obviously isn't. Then the code that calls the callback:

node_modules \\护照\\ lib目录\\中间件\\ authenticate.js

node_modules\passport\lib\middleware\authenticate.js

  strategy.success = function(user, info) {
    if (callback) {
      return callback(null, user, info);
    }

未通过这些参数。我在做什么错了?

doesn't pass those parameters. What am I doing wrong?

推荐答案

OK,我正在剥开我的自定义的认证和护照取而代之9小时昨天。得到节点的ORM博览会模型的要求之外,处理订货的东西流之间,我有点烧坏了。是准确的,我只需要code例子来更仔细阅读:

OK, I was working on ripping out my custom authentication and replacing it with passport for 9 hours yesterday. Between getting the node-orm to expos the model outside of the request and dealing with the flow of ordering things I was a little burned out. THe code examples are accurate, I just needed to read more carefully:

// traditional route handler, passed req/res
server.post(authPostRoute, function(req, res, next) {

  // generate the authenticate method and pass the req/res
  passport.authenticate('local', function(err, user, info) {
    if (err) { return next(err); }
    if (!user) { return res.redirect('/'); }

    // req / res held in closure
    req.logIn(user, function(err) {
      if (err) { return next(err); }
      return res.send(user);
    });

  })(req, res, next);

});

这篇关于护照回调身份验证不通过REQ和RES的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 23:22