Express JWT错误:socket.io初始身份验证中没有足够或太多的段

sjt*_*003 4 javascript authentication socket.io jwt express-jwt

在通过令牌和用户名的初始握手期间,我抓住了这个奇怪的错误 -

    { handle: 10,
      type: 'error',
      className: 'Error',
      constructorFunction: { ref: 11 },
      protoObject: { ref: 12 },
      prototypeObject: { ref: 3 },
      properties: 
      [ { name: 'stack',
          attributes: 2,
          propertyType: 3,
          ref: 3 },
        { name: 'arguments',
          attributes: 2,
          propertyType: 1,
          ref: 3 },
        { name: 'type',
          attributes: 2,
          propertyType: 1,
          ref: 3 },
        { name: 'message',
          attributes: 2,
          propertyType: 1,
          ref: 13 } ],
        text: 'Error: Not enough or too many segments' }
Run Code Online (Sandbox Code Playgroud)

畸形的JWT?初始令牌格式错误?

sjt*_*003 6

据我所知,这个错误是解析引用不再在db中的用户的JWT的未捕获异常的结果 - 更常见的情况是当bcrypt比较或者你正在使用的任何东西时发现哈希的比较是false - 这是我考虑过的 - 没有找到我没有找到的用户.当我考虑到这个时,错误就消失了.


Pyt*_*tth 6

如果您使用的是简单JWT,则通过查看源代码,我们可以看到此错误是由于令牌的格式不正确引起的。

//...

var segments = token.split('.');
if (segments.length !== 3) {
  throw new Error('Not enough or too many segments');
}
Run Code Online (Sandbox Code Playgroud)

  • 我不同意这些编辑。这个 `token` 变量来自哪里?省略号至少表明上面有其他代码未包含在我的答案中。 (2认同)