socket.io-client-swift icon indicating copy to clipboard operation
socket.io-client-swift copied to clipboard

set parameter for handshake.auth.token

Open ajijoyo opened this issue 4 years ago • 7 comments

I have question On server

io.on('connection', function (socket) {
  console.log('token: ' + socket.handshake.auth.token);
});

My question is how to set parameter on ios client since there is no enum for auth i have tried

SocketManager(socketURL: URL(string: "https://xxxx/")!, config: [.log(true), .compress, .path("/api/messenger/socket.io"), .connectParams(["token": Auth.token]))

but not work always fail

data =     {
        content = "Authentication error 01";
};
message = "not authorized";

ajijoyo avatar Apr 17 '21 06:04 ajijoyo

I tried the same as @ajijoyo and also got the same "not authorised" message. Please advise how to set the parameter for the handshake.auth.token.

kmphua avatar May 17 '21 22:05 kmphua

got the same problem, did you guys manage to make it work?

vUriarte avatar Jun 02 '21 17:06 vUriarte

actually, I didn't solve it, I suggested server to read from header instead

ajijoyo avatar Jun 03 '21 02:06 ajijoyo

If anyone is still interested, I solved it with the following:

let manager = SocketManager(socketURL: url, config: [.compress])
manager.socket.connect(withPayload: ["auth": "xxx"])

nzapponi avatar Jun 30 '21 08:06 nzapponi

Yeah, I ended up doing the same thing. It appears that passing the auth info via payload when connecting does the job!

vUriarte avatar Jul 02 '21 14:07 vUriarte

@nzapponi is it still working for you with latest socket library ?

I’m trying to use code sample which you provided and it won’t compile because can’t find such method .

romaHerman avatar Sep 23 '21 20:09 romaHerman

@nzapponi thanks man. that works. I'm using the latest version.

binarysid avatar Mar 05 '24 17:03 binarysid