最佳答案
如何验证套接字.io 连接?我的应用程序使用来自另一个服务器(python)的登录端点来获取令牌,当用户在节点端打开套接字连接时,我如何使用该令牌?
io.on('connection', function(socket) {
socket.on('message', function(message) {
io.emit('message', message);
});
});
客户方面:
var token = sessionStorage.token;
var socket = io.connect('http://localhost:3000', {
query: 'token=' + token
});
如果令牌是在 python 中创建的:
token = jwt.encode(payload, SECRET_KEY, algorithm='HS256')
如何使用此令牌验证节点中的套接字连接?