Socket.io授权,“;找不到授权标头";

Socket.io授权,“;找不到授权标头";,socket.io,authorization,Socket.io,Authorization,尝试向我的实时应用程序添加授权时,我在chrome控制台中收到以下消息: socket.io-parser decoded 4{"message":"No Authorization header was found","code":"credentials_required", "type":"UnauthorizedError"} 以下是我的代码(我使用angular fullstack): socket.service.js(客户端) socketio.js(服务器端) “smthing

尝试向我的实时应用程序添加授权时,我在chrome控制台中收到以下消息:

socket.io-parser decoded 4{"message":"No Authorization header was found","code":"credentials_required", "type":"UnauthorizedError"}
以下是我的代码(我使用angular fullstack):

socket.service.js(客户端)

socketio.js(服务器端)


“smthing”从不打印。如果我删除了授权部分,一切都正常工作。我觉得这很直截了当。。。任何帮助都会很好

实际上是正确的语法:

var ioSocket = io(null, {
    query: {       
        token: Auth.getToken()                   
    }
});

我能够在自己的环境中解决这个问题。我使用这个片段,尽管在解决根问题之前我遇到了一些问题

io.set('authorization', socketioJwt.authorize({
    secret: jwtSecret,
    handshake: true
}));
根本问题是没有将
socketio jwt所需的
令牌添加到请求
查询中。如果检查socketio jwt/lib/index.js,您将看到如下代码:

//get the token from query string
    if (req._query && req._query.token) {
      token = req._query.token;
    }
    else if (req.query && req.query.token) {
      token = req.query.token;
    }
这意味着您应该能够在此处记录
query
\u query
的值,并查看您的令牌

如果不能,则必须确保在socket.io客户端上为查询设置令牌。典型的方法是将其添加到
connectParams

在iOS/Swift客户端中,如下所示:

self.socket = [[SocketIOClient alloc] initWithSocketURL:@"localhost:8091" 
                        options:@{
                                   @"connectParams" : @{@"token" : <my_token>}
                                  }];
self.socket=[[SocketIOClient alloc]initWithSocketURL:@“localhost:8091”
选项:@{
@“connectParams”:@{@“令牌”:
}];

您有没有找到解决方案?我遇到了同样的问题
//get the token from query string
    if (req._query && req._query.token) {
      token = req._query.token;
    }
    else if (req.query && req.query.token) {
      token = req.query.token;
    }
self.socket = [[SocketIOClient alloc] initWithSocketURL:@"localhost:8091" 
                        options:@{
                                   @"connectParams" : @{@"token" : <my_token>}
                                  }];