Socket IO Swift Client add authentication headers after connection

Using Socket.IO swift client , how can you add headers like authorization headers after connection? Currently, when configuring the client, you can provide parameters for connectParams

and extraHeaders

, both of which are only sent to the original connection.

I want to connect a client, ask the client to invoke the authentication method on the server, get a token back, and THEN attach that token to all future sockets, but it doesn't seem like there is a way to do this.

+3


source to share


1 answer


You can send another event immediately after connecting, which contains your authentication details;

socket.on("connect") { data, ack in
    socket.emitWithAck("authenticate", token).timingOut(after: 0, callback: { dataArray in

    })
}

      



and then you can authenticate or delete the connection on the server side.

0


source







All Articles