【问题标题】:unauthorized using passport viA WEBSERVICE通过 WEBSERVICE 未经授权使用护照
【发布时间】:2018-02-20 01:10:00
【问题描述】:

我正在使用 Passport.js,但是当我进入 else 时,如果它给了我未经授权的错误。我们在这里调用网络服务。当我进入 else if(exists) 时,我想发送响应 oto webservice。有什么想法吗?

passport.use('local-signup-nti', new LocalStrategy({
        // by default, local strategy uses username and password, we will override with email
        usernameField: 'email',
        passwordField: 'password',
        passReqToCallback: true // allows us to pass back the entire request to the callback
    },
function (req, email, password, done) {
            user.emailExists(email, function (err, exists) {
                if (err)
                    return done(err);
                else if (exists) {
                        req.userDetails=1;
                     return done(err, req.userDetails);
                } else {

    }

【问题讨论】:

    标签: node.js passport.js passport-local


    【解决方案1】:

    done 函数必须始终被调用,否则,passport 将无法正常工作。

    因此,您必须将结果传递给done 函数并通过回调函数passport.authenticate 以您想要的方式处理结果。

    看例子:

    app.get('/protected', function(req, res, next) {
            passport.authenticate('local-signup-nti', function(err, user, info) {
              if (err) { return next(err) }
              if (!user) { return res.redirect('/whereEverYouWant') }
              res.redirect('/toYourWebService');
            })(req, res, next);
          });
    

    希望清楚!

    【讨论】:

      猜你喜欢
      • 2018-03-18
      • 2018-02-04
      • 2019-10-31
      • 2019-02-01
      • 1970-01-01
      • 2017-10-18
      • 2019-01-05
      • 2020-04-19
      • 2021-09-24
      相关资源
      最近更新 更多