phonegap-websocket icon indicating copy to clipboard operation
phonegap-websocket copied to clipboard

Socket.IO With 'authorization'

Open alanjames1987 opened this issue 12 years ago • 4 comments

In order to have Socket.IO and Express share the same session data a sessionStore and cookie have to be used. This works great on browers, but PhoneGap is giving me problems.

I referenced your Socket.IO example and the socket.on('error'... event keeps firing. I looked at my Socket.IO log and this is the error I am getting when PhoneGap tries to connect.

GET /socket.io/1/?t=1396314433839 302 2ms - 82b
   debug - authorized
   warn  - handshake error MISSING_COOKIE

I'm using PhoneGap 3.4.0 on Android 4.2.2 on a Galaxy Nexus.

Do you know how I can fix this?

alanjames1987 avatar Apr 01 '14 02:04 alanjames1987

@alanjames1987 that's strange. I'm using a similar setup here (cookie based auth with express) and things are working fine for me. What version of socket.io-client do you use? Do things work fine for you when testing from the browser?

mkuklis avatar Apr 01 '14 02:04 mkuklis

I've been using 0.9.6 as the client and server. I've been using socket.io-session to connect my Express and Socket.IO sessions.

From what I can see it looks like PhoneGap just never works with cookies. I might be wrong on this but it looks like I will have to write my own authorization function to handle different requests from browsers or PhoneGap.

This should be no problem, but it's just a drag that PhoneGap didn't behave exactly like browsers do.

alanjames1987 avatar Apr 01 '14 05:04 alanjames1987

I'm having the same issue http://stackoverflow.com/questions/38550654/socket-io-auth-doesnt-work-on-cordova-mobile

eldyvoon avatar Jul 24 '16 09:07 eldyvoon

@eldyvoon I would suggest switching from a cookie based auth to a token based.

mkuklis avatar Jul 25 '16 01:07 mkuklis