如何在使用postman连接到socket.io时传递身份验证令牌?

问题描述 投票:0回答:3

这就是我将身份验证信用(映射)添加到 socket.io 中的套接字的方式:

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

尽管使用 POSTMAN 连接时没有这样的身份验证选项。 我尝试设置“auth”标头,然后将令牌传递到那里,但这也不起作用。然后我尝试使用 {"token" : TOKEN} 发送一个“auth”标头,但这不起作用。

dart websocket socket.io postman
3个回答
5
投票

现在 Postman 还不支持对象身份验证,您必须使用原始 websocket 并发送消息 40{"token":"123"} ,这是发送带有 token 的连接的包格式。

Raw socket postman example

这里讨论如何发送验证paylod https://github.com/socketio/socket.io/discussions/4072

这里是有关socket.io协议的信息 https://github.com/socketio/socket.io-protocol


2
投票

如果想使用socketIO postman。 而不是在 auth 中保存令牌, 您可以带标题发送。

const token = socket.handshake.headers.access_token;

邮递员请求

1


0
投票

应用程序经常在auth中使用token,但postman不支持。 您将令牌放入邮递员标头中,您的服务器以这种方式获取令牌:

const Authorization = socket.handshake.auth?.token || socket.handshake.headers?.token;
© www.soinside.com 2019 - 2024. All rights reserved.