Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js + express.js + socket.io authorization: no cookie

I'm having trouble getting the "cookie" data from my socket.io authorization.

io.configure(function() {
io.set('authorization', function (data, cb) {
   console.log(data);
   // data.headers.cookie <-- should be the cookie
});
});

So what it prints is:

{ headers: 
 { host: 'frisr.dk:1000',
 connection: 'keep-alive',
 origin: 'http://frisr.dk',
 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.106 Safari/535.2',
 accept: '*/*',
 referer: 'http://frisr.dk/',
 'accept-encoding': 'gzip,deflate,sdch',
 'accept-language': 'da-DK,da;q=0.8,en-US;q=0.6,en;q=0.4',
 'accept-charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3' },
address: { address: '80.71.135.24', port: 53549 },
time: 'Sun Nov 06 2011 22:34:12 GMT+0000 (UTC)',
query: { t: '1320610986125' },
url: '/socket.io/1/?t=1320610986125',
xdomain: true,
secure: undefined,
issued: 1320618852796 }

you can check the code out here: http://frisr.dk

Why is the cookie not available?

like image 392
Danielss89 Avatar asked Nov 06 '11 20:11

Danielss89


2 Answers

Have a gander at your host. What is your client connecting to? I was having an issue with expressjs 3.* and Socket.io as well, but I was issuing my client to connect as:

io.connect(127.0.0.1);

Instead of

io.connect('localhost');

Now to hack together the lovely new parsing routine.

https://groups.google.com/forum/?fromgroups=#!topic/express-js/II3eIM9HHQY

like image 100
user1835017 Avatar answered Oct 21 '22 18:10

user1835017


Cookie is not beeing set during handshake request. Probably cookie is already set for different server/domain and thats why on your second server it exists in your data object. Check if cookie is beeing set for this domain in firebug ot smth.

like image 37
nethead Avatar answered Oct 21 '22 18:10

nethead