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

How to send auth parameters ?

Open romaHerman opened this issue 3 years ago • 7 comments

Our server want to read parameter like this

      EIO: '4',
      transport: 'polling',
      t: 'NmJJKTk'
    },
    auth: {
      public: '<>',
      access: '<>',
      timestamp: <>
    }```

In android socket io client there is parameter Auth 
But I can't find one on iOS 

and solution from other similar questions doesn't work for me
(that solution won't event compile) 
other options with payload also didn't work somehow 

I'm using latest  client 

Can anyone help me please ?

romaHerman avatar Sep 24 '21 05:09 romaHerman

I've eventually figured this out so answering my own question:

this is working code:


  chatSocketManager = SocketManager(socketURL: socketURL, config: [.log(true), .compress])             
 chatSocketManager.defaultSocket.on(clientEvent: .connect) {data, ack in
            print("socket connected")
           self.chatSocketManager.defaultSocket.joinNamespace()
        }
 let dict =  [ "access" : accessToken,
                         "public": publicToken,
                         "timestamp" : "\(timeStamp)"]
chatSocketManager.defaultSocket.connect(withPayload: dict)

withPayload automatically wraps dict into auth:dict

romaHerman avatar Sep 24 '21 07:09 romaHerman

I've eventually figured this out so answering my own question:

this is working code:


  chatSocketManager = SocketManager(socketURL: socketURL, config: [.log(true), .compress])             
 chatSocketManager.defaultSocket.on(clientEvent: .connect) {data, ack in
            print("socket connected")
           self.chatSocketManager.defaultSocket.joinNamespace()
        }
 let dict =  [ "access" : accessToken,
                         "public": publicToken,
                         "timestamp" : "\(timeStamp)"]
chatSocketManager.defaultSocket.connect(withPayload: dict)

withPayload automatically wraps dict into auth:dict

do use the latest Socket pod version? After I updated pods and Xcode to version 13 I dont have: connect(withPayload: ..) anymore ? Do you have that issue

Ant-Adis avatar Oct 19 '21 16:10 Ant-Adis

Hi @Ant-Adis here is my pod file lock :

  • Socket.IO-Client-Swift (16.0.1):
    • Starscream (~> 4.0)

Could you post code you're trying to compile ?

romaHerman avatar Oct 20 '21 06:10 romaHerman

@romaHerman I had to revert pod installs and currently Im using Socket IO through Package Dependencies, version: 16.0.1 next major, with this I dont have any issues

Ant-Adis avatar Oct 20 '21 09:10 Ant-Adis

I've eventually figured this out so answering my own question:

this is working code:


  chatSocketManager = SocketManager(socketURL: socketURL, config: [.log(true), .compress])             
 chatSocketManager.defaultSocket.on(clientEvent: .connect) {data, ack in
            print("socket connected")
           self.chatSocketManager.defaultSocket.joinNamespace()
        }
 let dict =  [ "access" : accessToken,
                         "public": publicToken,
                         "timestamp" : "\(timeStamp)"]
chatSocketManager.defaultSocket.connect(withPayload: dict)

withPayload automatically wraps dict into auth:dict

@romaHerman withPayload automatically wraps dict into auth:dict -> Could you please let me know where you found this information? I checked the code and couldn't find any code that wraps the dictionary into an "auth" key. Thank you! 🙇‍♂️

kbw2204 avatar May 21 '24 07:05 kbw2204

Hey @kbw2204 I haven't that was trial and error process when I was trying different options and the backend team was telling me what they have on their end since Starscream library is used under the hood for sockets maybe it's somewhere there. I don't know

romaHerman avatar May 21 '24 07:05 romaHerman

Ah, I see. I can check with the backend team to confirm. Thank you for your response! 🙇‍♂️

kbw2204 avatar May 21 '24 09:05 kbw2204