socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

Socket.io 1.0.0-pre Authorize (Handshake data)

Open cloudgifts opened this issue 12 years ago • 7 comments

So, I know the handshake data is now socket.request, but I am not seeing my query as I would expect:

Client (actually a server using socket.io-client): var socket = socketIoClient('https://example.com:443/?key=12345');

Server: socketIoObject.use(function(socket, next) { console.log('socket.request: ' + util.inspect(socket, {depth : null})); });

No where in the socket object do I see my query key. I would like to use this key for authorization. Where can I find it?

cloudgifts avatar Apr 10 '14 18:04 cloudgifts

@cloudcash this is a good find. I just submitted a pull request that should resolve this problem here https://github.com/LearnBoost/socket.io-client/pull/656.

Once it is merged, you should be able to get the query stuff at socket.request.query.

kevin-roark avatar Apr 10 '14 20:04 kevin-roark

@cloudcash Here's an ammendment. My PR should make the query accessible by parsing socket.request.url.

kevin-roark avatar Apr 10 '14 23:04 kevin-roark

Thanks, I'll give it a shot :+1:

cloudgifts avatar Apr 11 '14 00:04 cloudgifts

@cloudcash did it work out? :) Wondering if we can close the issue.

rase- avatar May 24 '14 19:05 rase-

Hello, same problem here, using angular-fullstack. I checked lib/index.js file but I couldn't find parsed.href. Any idea ?

hypervillain avatar Oct 26 '14 11:10 hypervillain

You can use this way Client: var socket = io.connect('http://localhost:3000', { query: "key=12345" });

Server: io.set('authorization', function (handshakeData, callback) { callback(null, true); });

io.sockets.on('connection', function(socket){ var key = socket.handshake.query.key; // your key });

cong88 avatar Nov 30 '14 05:11 cong88

Thank you for your answer ! Key is undefined this way, unfortunately. You can see this stackoverflow question for something I tried: http://stackoverflow.com/questions/26993447/socket-io-handshake-fails-on-site-but-not-on-localhost

hypervillain avatar Dec 05 '14 14:12 hypervillain