Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass auth token while connecting to socket.io using postman?

This is how I've been adding my auth creds (map) to a socket in socket.io:

socket = io(
    url.toString(),
    OptionBuilder()
        .setTransports(['websocket'])
        .disableAutoConnect()
        .enableForceNew()
        .enableForceNewConnection()
        .setAuth({"token": token})
        .build());

Although there is no such auth option while connecting using POSTMAN. I tried setting a "auth" header and then passing the token there, but that did not work either. Then I tried to send a "auth" header with {"token" : TOKEN}, that did not work.

like image 901
Advait Avatar asked Oct 23 '25 11:10

Advait


2 Answers

If want to use socketIO postman. instead of saving token in auth, you can send with header.

const token = socket.handshake.headers.access_token;

Postman request

1

like image 84
Bivas Biswas Avatar answered Oct 25 '25 10:10

Bivas Biswas


Now days the object auth is not supported by Postman yet, insted you must use the raw websocket and send the message 40{"token":"123"} who is the package format to send a connection with token.

Raw socket postman example

Here is a discussion about how to send authentication paylod https://github.com/socketio/socket.io/discussions/4072

Here is information about socket.io protocol https://github.com/socketio/socket.io-protocol

like image 30
Rafael Vigueras Avatar answered Oct 25 '25 11:10

Rafael Vigueras



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!