Created
October 31, 2012 13:15
-
-
Save 3rd-Eden/3986964 to your computer and use it in GitHub Desktop.
Socket.IO / Express / Connection sid parsing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Setup authorization for socket.io to ensure that the user actually has | |
// access to this socket.io instance | |
io.set('authorization', function authorization(handshake, done) { | |
if (!handshake.headers.cookie) return done('No cookie transmitted', false); | |
var sessionID = /connect.sid\=([^;]+)/g.exec(handshake.headers.cookie); | |
if (sessionID && sessionID.length) handshake.sessionID = unescape(sessionID[1]).split('.')[0].slice(2); | |
// Only allow connections that are logged in. | |
sessions.get(handshake.sessionID, function (err, sess) { | |
done(err, sess && sess.loggedIn, handshake); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment