express 使用passport 出现 passport.initialize() middleware not in use错误
app.get("/login/github", passport.authenticate("github", {session: false}));
app.get("/login/github/callback", passport.authenticate("github", {
session: false,
failureRedirect: '/login',
successFlash: '登陆成功!'
}), function (req, res) {
req.session.user = {name: req.user.username, head: "https://gravatar.com/avatar/" + req.user._json.gravatar_id + "?s=48"};
res.redirect('/');
});
app.js里面也添加了:
app.use(passport.initialize());
passport.use(new GithubStrategy({
clientID: "xxx",
clientSecret: "xxx",
callbackURL: "xxx"
}, function(accessToken, refreshToken, profile, done) {
done(null, profile);
}));
2 回复
app.js文件 app.use(express.cookieParser()) app.use(express.session({secret: ‘blog.fens.me’, cookie: { maxAge: 60000 }})); app.use(passport.initialize()); app.use(passport.session());
详细使用参考文章 http://blog.fens.me/nodejs-express-passport/ http://blog.fens.me/nodejs-oauth-passport/
我知道问题了,是因为我git账号没有设置公开邮箱。您的系列教程讲的不错。