护照身份验证未调用Passport localstrategy

时间:2019-02-05 06:20:02

标签: javascript passport.js

我正在使用护照进行身份验证。我有登录API,其中有护照身份验证。返回(null,false)。 但是,当地战略并未得到应有的重视。

const bodyParser = require('body-parser');
const express = require('express');
const passport = require('passport');
// require('./passport')(passport);
const LocalStrategy = require('passport-local').Strategy;
const ADMIN = 'admin';
const ADMIN_PASSWORD = 'password';
const app = express();

app.use((req, res, next) => {
  res.setHeader("Access-Control-Allow-Origin", "http://localhost:3000");
  res.setHeader(
    "Access-Control-Allow-Methods",
    "GET, POST, OPTIONS, PUT, PATCH, DELETE"
  );
  res.setHeader(
    "Access-Control-Allow-Headers",
    "X-Requested-With,content-type"
  );
  res.setHeader("Access-Control-Allow-Credentials", true);
  next();
});

app.use(bodyParser.urlencoded({
    extended: true
}));
app.use(bodyParser.json());

passport.use('local', new LocalStrategy(function(username , password, done) {
        console.log('in passport',username,password);
            if (username === ADMIN && password === ADMIN_PASSWORD) {
                done(null, 'TOKEN');
                return;
              }
              done(null, true);
    }));


app.post('/login', function(req, res) {

  passport.authenticate('local', function(err, user) {
    console.log(err,user);
  })(req, res);

});


app.listen(4000, () => {
  console.log("REST server started on port 4000");
});

我无法找到这里缺少的东西。我还检查了正文参数是否正确解析。

0 个答案:

没有答案