UnauthorizedError:无效的算法表达式jwt



我在我的网站上显示一些数据,从节点服务器返回。直到今天,它的工作都很完美。现在我得到以下错误在我的服务器控制台,当我去我的网页。我使用Auth0登录用户。

UnauthorizedError: invalid algorithm
    at C:workspaceNewMyAppnode_modulesexpress-jwtlibindex.js:100:22
    at C:workspaceNewMyAppnode_modulesexpress-jwtnode_modulesjsonwebtokenindex.js:155:18
    at nextTickCallbackWith0Args (node.js:420:9)
    at process._tickCallback (node.js:349:13)

有什么问题吗?

HS256不太安全,因为它是对称的(在客户端和服务器之间共享相同的秘密)。看看这个问题:RS256和HS256:有什么区别?

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

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_AUDIENCE_OR_CLIENT_ID>,
  issuer: 'https://<YOUR_AUTH0_DOMAIN>/',
  algorithms: ['RS256'],
})
app.use(jwtCheck)

我也遇到了同样的问题。我使用Auth0来登录用户。您必须检查算法类型。

如果您使用Auth0,请转到

Client -> Settings -> Advanced Settings -> OAuth

,检查算法类型。必须是HS256。

如果你没有使用Auth0,那么检查算法类型也

使用

expressJwt({
  secret: process.env.JWT_SECRET,
  algorithms: ['sha1', 'RS256', 'HS256'],
})

在您的expressJwt参数()中使用下面的代码:

algorithms: ['sha1', 'RS256', 'HS256'],   

Copy the algorithms and change/paste it on your function this methods helps me in postman, paw, robo 3t

最新更新