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

More control over auth property

Open magyarlaszlo opened this issue 10 months ago • 2 comments

Hello!

I would like to request a small change regarding the auth parameter. Currently, it is limited to a Map<String, String>, but for my use-case it would be nice to have more control over it. As I can see in the code, this map is converted into a JSONObject before it is being sent.

My request would be to change the Manager.Options class' auth property to a JSONObject, so I can send anything I want in auth, not just a map of strings. After the change, the Manager.Options class would look like this:

` public static class Options extends io.socket.engineio.client.Socket.Options {

    public boolean reconnection = true;
    public int reconnectionAttempts;
    public long reconnectionDelay;
    public long reconnectionDelayMax;
    public double randomizationFactor;
    public Parser.Encoder encoder;
    public Parser.Decoder decoder;
    public JSONObject auth;

    /**
     * Connection timeout (ms). Set -1 to disable.
     */
    public long timeout = 20000;

    // helper method for easier migration
    public void authMap(Map<String, String> authMap) {
        this.auth = new JSONObject(authMap);
    }
}`

Also, the Socket class needs a little change: ` private final JSONObject auth;

private void onopen() {
    logger.fine("transport is open - connecting");

    if (this.auth != null) {
        this.packet(new Packet<>(Parser.CONNECT, this.auth));
    } else {
        this.packet(new Packet<>(Parser.CONNECT));
    }
}`

Thanks in advance!

magyarlaszlo avatar Feb 20 '25 22:02 magyarlaszlo

I created a pull request with the required changes here: https://github.com/socketio/socket.io-client-java/pull/781

laszlomagyardocler avatar Feb 21 '25 08:02 laszlomagyardocler

We need the same changes to make it more extensive!

kyrylzotov avatar Feb 21 '25 09:02 kyrylzotov