Skip to content

More control over auth property #780

Open
@magyarlaszlo

Description

@magyarlaszlo

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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions