title: How to use passport with express and socket.io?
body: <p>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 <code>everyauth</code> but I didn't like to work with promises.</p>
  
  <p>Current situation:</p>
  
  <p>Authentication through passport (facebook strategy) is successful, a <code>session.sid</code> 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 <code>socket.io</code> through <code>socket.handshake.headers.cookie</code>. </p>
  
  <p>If I understood the passport concept correctly, after successful <code>authentication passport.serializeUser</code> 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:</p>
  
  <pre><code>passport.serializeUser(function(user, done) {
    done(null, user.email);
  });
  </code></pre>
  
  <p>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. </p>
  
  <pre><code>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?
  });
  </code></pre>
  
  <p>So if I am not mistaken, the task is now to use <code>deserializeUser</code> to access the corresponding email address.</p>
  
  <p>How would I do that? Any pointers are highly appreciated.</p>