我使用以下(有护照,但没关系):
io.set('authorization', function(data, accept) {
var getCookieSession = require('./lib/cookie_session');
var session = getCookieSession(data.headers, {
key: 'YOUR KEY',
secret: 'YOUR SECRET'
});
if (session.passport.user) {
accept(null, true);
} else {
accept(null, false);
}
});
getCookieSession 是以下模块:
var connect = require('connect');
var cookieParser = connect.cookieParser;
var cookieSession = connect.cookieSession;
module.exports = function(headers, opts) {
var key = opts.key || '_session';
var secret = opts.secret || '';
var req = { headers: headers, originalUrl: "/" };
var res = { on: function() {} };
var next = function () {};
cookieParser(secret)(req, res, next);
cookieSession({ key: key })(req, res, next);
return req.session;
};