I am currently trying to set up a basic authentication system for my node.js app. For now I am using express (3.0.0rc5), passport (0.1.12) and socket.io (0.9.10) with Mongoose as Store for session data. I have also been playing around with everyauth but I didn't like to work with promises.
Current situation:
Authentication through passport (facebook strategy) is successful, a session.sid cookie is set on the client after the redirect and I am able to see a session document in my database. I can access the session cookie in socket.io through socket.handshake.headers.cookie.
If I understood the passport concept correctly, after successful authentication passport.serializeUser is called which enables me to add information to the session. In my case the most important information is the email, so I set the serializer up in the following way:
passport.serializeUser(function(user, done) {
done(null, user.email);
});
Now I am at the point where I have to use only the cookie information in my socket.io event to extract the email address from the session.
var connect = require('connect'),
parseSignedCookie = connect.utils.parseSignedCookie,
cookie = require('express/node_modules/cookie');
io.on('connection', function(socket) {
if(socket.handshake.headers.cookie) {
var cookie = cookie.parse(socket.handshake.headers.cookie);
var sessionID = parseSignedCookie(cookie['connect.sid'], 'secret');
}
});
passport.deserializeUser(function(id, done) {
// so, what is supposed to be done here?
});
So if I am not mistaken, the task is now to use deserializeUser to access the corresponding email address.
How would I do that? Any pointers are highly appreciated.