aviddiviner/Socket.IO-sessions — Issue #4: Extract session id from .handshake property
Author: nponeccop
Created: 2012-02-25 16:21:52+00:00
State: open

Socket.io now allows more direct access to client cookies. See https://github.com/LearnBoost/socket.io/wiki/Authorizing

Two possible solutions are:

1) To use `io.set('authorization', function (handshakeData, callback) {})` and get cookie from the `handshakeData` parameter.

2) To use `socket.handshake` property as `handshakeData` is saved there.

Something in the lines of

```coffeescript
processSession = (socket) ->
return true if socket.sessionId

# Parse session ID from initial hankshake data
cookie = socket.handshake.headers.cookie
if cookie && (i = cookie.indexOf('connect.sid')) >= 0
socket.sessionId = cookie.substr(i+12, 24)
else
console.log('Warning: connect.sid session cookie not detected. User may have cookies disabled or session cookie has expired')
false
```