gpt4 book ai didi

node.js - 如何查看 JWT 中存储的数据?使用 auth0 和express-jwt

转载 作者:太空宇宙 更新时间:2023-11-04 01:55:18 25 4
gpt4 key购买 nike

现在我相信我已经正确设置了大部分内容。 Auth0 将 jwt 保存到客户端,然后客户端将其用于将来的请求。我使用express-jwt来验证 token 。通过阅读 Auth0 文档,我认为我需要客户端 key (当我使用它来解码 jwt 时,我收到一个奇怪的错误: UnauthorizedError: error:0906D06C:PEM routines:PEM_read_bio:no start line )所以我只是想知道这个 key 来自哪里?谢谢

  • 当前代码仅将 JWT 解码为其签名方案等:

    const jwtCheck = jwt({
    secret: jwks.expressJwtSecret({
    cache: true,
    rateLimit: true,
    jwksRequestsPerMinute: 5,
    jwksUri: '<a href="https://xelitexirish.eu.auth0.com/.well-known/jwks.json" rel="noreferrer noopener nofollow">https://xelitexirish.eu.auth0.com/.well-known/jwks.json</a>'
    }),
    audience: '<a href="https://www.shaunoneill.com" rel="noreferrer noopener nofollow">https://www.shaunoneill.com</a>',
    issuer: '<a href="https://xelitexirish.eu.auth0.com/" rel="noreferrer noopener nofollow">https://xelitexirish.eu.auth0.com/</a>',
    algorithms: ['RS256']
    });

最佳答案

根据OP的评论,要读取JWT主体的值,只需进行base64解码即可。您可以为此使用库,例如​​ jwt-decode对于nodejs。

请参阅下面的示例用法(取自 lib 的 README):

var jwtDecode = require('jwt-decode');
var token = 'eyJ0eXAiO.../// jwt token';

var decoded = jwtDecode(token);
console.log(decoded);

/* prints:
* { foo: "bar",
* exp: 1393286893,
* iat: 1393268893 }
*/

您的 token (此处指 ID token )中的声明取决于您在进行身份验证时提供的范围。例如,如果您使用 scope: openid profile email,您将获得 ID token 中返回的所有内容。

这里,假设 JWT 已使用库进行验证,现在您拥有了想要读取一些来自正文的声明的 JWT。

关于node.js - 如何查看 JWT 中存储的数据?使用 auth0 和express-jwt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48198768/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com