【问题标题】:UnauthorizedError: jwt malformed error when authenticatingUnauthorizedError:身份验证时出现 jwt 格式错误的错误
【发布时间】:2019-12-23 16:30:58
【问题描述】:

我正在使用 Auth0 对我的 react 应用程序的用户进行身份验证。我一直在尝试访问服务器端的资源,但我不断收到 UnauthorizedError: jwt malformed as an Error。

我在社区论坛上关注了以下主题:https://community.auth0.com/t/unauthorizederror-jwt-malformed-in-express-js/7352 许多用户认为指南中的受众价值是错误的。指南中给出的受众是 https:///userinfo 但应该是“https://.auth0.com/api/v2/”,我已经进行了更改,但错误仍然存​​在。

这对某些人有效,但对我无效。 这是我一直遵循的指南:https://auth0.com/blog/react-tutorial-building-and-securing-your-first-app/

const checkJwt = jwt({
  secret: jwksRsa.expressJwtSecret({
    cache: true,
    rateLimit: true,
    jwksRequestsPerMinute: 5,
    jwksUri: `https://<domain>/.well-known/jwks.json`
  }),

  // Validate the audience and the issuer.
  audience: "https://<something>/api/v2/",
  issuer: `https://<something>/`,
  algorithms: ["RS256"]
});

这是我在快递方面编写的代码。

this.auth0 = new auth0.WebAuth({
      // the following three lines MUST be updated
      domain: "<Domain>",
      audience: "https://<Something>/api/v2/",
      clientID: "clientID",
      redirectUri: "http://localhost:3000/callback",
      responseType: "token",
      scope: "openid"
    });

这是写在应用前端的代码。

【问题讨论】:

    标签: express authentication jwt auth0


    【解决方案1】:

    我们的一位高级工程师对此提出了很好的建议,我将在下面分享:

    如果您还没有这样做,您应该执行以下步骤:

    1. 捕获你收到的令牌;例如,在开发中使用 console.log 语句。
    2. 查看捕获的令牌;它看起来像 JWT 吗?
    3. 如果它是 JWT 并且您可以在 jwt.io 解析它,则在尝试验证之前更新 API 以记录接收到的令牌;收到的 令牌与您期望的匹配?

    总之,试着采取一些措施,让你收集更多 信息。

    【讨论】:

      猜你喜欢
      • 2023-02-24
      • 2016-08-17
      • 2017-11-29
      • 2020-06-26
      • 1970-01-01
      • 2018-09-13
      • 2016-07-05
      • 2014-12-22
      • 1970-01-01
      相关资源
      最近更新 更多