通过 WEBSERVICE 未经授权使用护照

unauthorized using passport viA WEBSERVICE

我正在使用 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 {

    }

必须始终调用 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);
      });

希望清楚!