Wednesday, 15 January 2025
  13 Replies
  76 Visits
  Subscribe
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.
6 minutes ago
·
#2232
I'm trying to send a string array and it doesn't seem to work, like this:


const socket = io({
query: {
arr: ['a', 'b']
}
});


Tired with

WSSocketIO.SocketIO.Parameters := '&arr=[''a'',''b'']';



WSSocketIO.SocketIO.Parameters := '&arr=["a","b"]';



WSSocketIO.SocketIO.Parameters := '&arr=%5B%27a%27,%27b%27%5D';


and various other similar combinations, but nothing seem to work
17 hours ago
·
#2231
Use the parameters property, example:


WSSocketIO.SocketIO.Parameters := '&x=42';
19 hours ago
·
#2230
Ok. Thanks. The auth now works as expected. We also need to use query parameters. Is that something that you have support for?

https://socket.io/docs/v4/client-options/#query
4 days ago
·
#2229
Find below the link to download the trial for D11

https://www.esegece.com/download/samples/sgcWebSockets_D11.zip

Kind Regards,
Sergio
4 days ago
·
#2228
We're using Delphi 11.
4 days ago
·
#2227
Next month will be a new release, but I can compile a trial with this feature if you tell me which is your delphi version.
4 days ago
·
#2226
Ok. It seems to work with the sample. When will the trial version for Delphi be updated so we can test this further?
5 days ago
·
#2225
Hi,

I've added a new property "HandShakeAuthToken" to set the Authentication token. Find attached a compiled sample that use this new feature.

Kind Regards,
Sergio
Attachments (1)
5 days ago
·
#2224
No. The auth is in the payload when connecting to the namespace. See info in the socket io code:
https://github.com/socketio/socket.io/blob/main/packages/socket.io-client/lib/socket.ts

/**
* the authentication payload sent when connecting to the Namespace
*/
auth?: { [key: string]: any } | ((cb: (data: object) => void) => void);


/**
* Credentials that are sent when accessing a namespace.
*
* @example
* const socket = io({
* auth: {
* token: "abcd"
* }
* });
*
* // or with a function
* const socket = io({
* auth: (cb) => {
* cb({ token: localStorage.token })
* }
* });
*/
public auth: { [key: string]: any } | ((cb: (data: object) => void) => void);
5 days ago
·
#2223
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
5 days ago
·
#2222
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.
5 days ago
·
#2221
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
6 days ago
·
#2220
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
  • Page :
  • 1
There are no replies made for this post yet.
Submit Your Response
Upload files or images for this discussion by clicking on the upload button below.
Supported: gif,jpg,png,jpeg,zip,rar,pdf,pas,dfm,dpr,dproj,dpk
· Insert · Remove
  Upload Files (Maximum 10MB)