By Guest on Wednesday, 15 January 2025
Posted in General
Replies 4
Likes 0
Views 9
Votes 0
I'm testing the newest version of sgcWebSockets in Delphi to try to connect to a socket.io server.

The server I'm connecting to is using this type of auth:
https://socket.io/docs/v4/client-options/#auth

I can't see any documentation that this type of auth is supported. I've tried using TsgcWebSocketClient Authentication.Token, but that doesn't seem to work with this type of auth.
Hello,

It seems this auth requires to pass the token when opening the http request to get a new session, so you should use the event OnHTTPRequest of the Socket.io API, find below how to pass a bearer token example, just replace "your-token" by the correct value


procedure OnHTTPRequest(Sender: TObject; aRequest: TsgcWSSocketIOHTTPRequest);
begin
aRequest.Headers.Add('Authorization: Token your-token');
end;


If doesn't work, and you can provide the server where you must connect please provide more details and I'll check in my machine.

Kind Regards,
Sergio
·
8 hours ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi. It's not a part of the headers. It's sent during the CONNECT in the protocol. See the example here under 'with an additional payload':
https://socket.io/docs/v4/socket-io-protocol/#connection-to-a-namespace
·
7 hours ago
·
0 Likes
·
0 Votes
·
0 Comments
·
It is possibly also a part of the handshake outside of the header. See info here:
https://socket.io/docs/v4/server-socket-instance/#sockethandshake

Similar to the HandShakeTimestamp you've already implemented.
·
7 hours ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello,

The Socket handshake is just an HTTP GET request with some parameters. According the url:

https://socket.io/docs/v4/server-socket-instance/#sockethandshake

The Auth is passed as a payload, but a HTTP GET request hasn't a payload, it's not a POST, so I assume they are referring to pass an Authorization header like in the example I've sent previously. Did you tested it? it doesn't work?

Kind Regards,
Sergio
·
1 hour ago
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post