我想知道如何配置passport.socketio
.
我阅读了文档,但仍然可以了解如何设置store
属性。
我正在使用passport-local
.
这是我的代码(相关部分):
一些配置:
app.use( express.cookieParser() );
app.use(express.methodOverride());
// use express.session before passport, so that passport session will work
app.use(express.session({ secret: 'somerandomcod3' }));
// Initialize Passport! Also use passport.session() middleware, to support
// persistent login sessions (recommended).
app.use(passport.initialize());
app.use(passport.session());
护照.socketio 配置
io.set("authorization", passportSocketIo.authorize({
cookieParser: express.cookieParser,
key: 'express.sid',
secret: 'somerandomcod3',
store: express.session, // not working tried also a couple others
fail: function(data, accept) {
accept(null, false);
},
success: function(data, accept) {
accept(null, true);
}
}));
我的本地策略
var LocalStrategy = require('passport-local').Strategy ;
passport.use(new LocalStrategy(function(username, password, done) {
db.userModel.findOne({ username: username }, function(err, user) {
if (err) { return done(err); }
if (!user) { return done(null, false, { message: 'Unknown user ' + username }); }
user.comparePassword(password, function(err, isMatch) {
if (err) {
return done(err);
}
if(isMatch) {
return done(null, user);
} else {
return done(null, false, { message: 'Invalid password' });
}
});
});
}));
所以问题是我怎样才能获得 session store 或更好。?!