cannot set property on socket.io handshake object

I am trying to add a custom attribute to a socket.io handshake and pass it to the socket object at each connection.

Below a very minimal set up of what I am doing:

var app = express();
var http = require("http").Server(app);

var io = require("socket.io")(http);

io.set('authorization', function(data, callback){
  data.foo = 'bar';
  callback(null, true);
});

The above should give access to a foo property on the socket.handshake object, however, doing the following:

io.sockets.on('connection', function (socket) {
    console.log(socket.handshake.foo); //This should return bar
});

Returns an undefined.

In Socket.IO 1.0, there is no more handshake object, it's been replaced by socket.request.

That should work :

io.sockets.on('connection', function (socket) {
    console.log(socket.request.foo);
});

Look here for more info on the differences between 0.9 and 1.0.

Keep in mind that most of the resources/tutorials you'll find online will be using Socket.IO 0.9, so the knowledge on this page is very useful ;)