UnauthorizedError:无效的algorithmexpress-jwt

我在我的网站上显示了一些从节点服务器返回的数据。 直到今天,它都是完美的。 现在,当我进入我的网页时,我的服务器控制台上出现错误。 我使用Auth0login用户。

 UnauthorizedError: invalid algorithm at C:\workspace\New\MyApp\node_modules\express-jwt\lib\index.js:100:22 at C:\workspace\New\MyApp\node_modules\express-jwt\node_modules\jsonwebtoken\index.js:155:18 at nextTickCallbackWith0Args (node.js:420:9) at process._tickCallback (node.js:349:13) 

可能是什么问题?

我有同样的问题。 我使用Auth0login用户。 你必须检查algorithmtypes。

如果你使用Auth0,然后去

客户端 – >设置 – >高级设置 – > OAuth

并检查algorithmtypes。 它必须是HS256。

如果你不使用Auth0,那么也检查algorithmtypes。

由于HS256是对称的,因此HS256的安全性较差(在客户端和服务器之间共享相同的秘密)。 看到这个问题: RS256 vs HS256:有什么区别?

您可以使用node-jwks-rsa模块来维护RSA256以检索签名密钥:

 import jwt from 'express-jwt' import jwksRsa from 'jwks-rsa' const secret = jwksRsa.expressJwtSecret({ cache: true, rateLimit: true, jwksRequestsPerMinute: 5, jwksUri: 'https://<YOUR_AUTH0_DOMAIN>/.well-known/jwks.json', }) const jwtCheck = jwt({ secret: secret, audience: <YOUR_AUTH0_CLIENT_ID>, issuer: 'https://<YOUR_AUTH0_DOMAIN>/', algorithms: ['RS256'], }) app.use(jwtCheck)