【问题标题】:How would I decode info from idToken using express-Jwt?如何使用 express-Jwt 解码来自 idToken 的信息?
【发布时间】:2021-08-25 20:59:19
【问题描述】:

我的应用程序使用 Google 的身份验证和浏览器将 idToken 发送到我的 API 服务器。我使用checkIfAuthenticated 来验证 idToken,一旦验证成功,就需要从中解码/提取信息。但我不知道如何解码/提取。

这是验证和路由的方式:

const jwksRsa = require('jwks-rsa');
const expressJwt = require('express-jwt');

const checkIfAuthenticated = () =>
{
    var googleUri = "https://www.googleapis.com/oauth2/v3/certs";
    expressJwt({
        secret: jwksRsa.expressJwtSecret({
            cache: true,
            rateLimit: true,
            jwksUri: googleUri
        }),
        algorithms: ['RS256']
    });
    // try to decode but gave me a definition of ƒ (req, res, next){...
    var data = expressJwt({secret: googleUri, requestProperty: 'auth', algorithms: ['RS256'] }); 
}

module.exports = app =>
{
    app.post("/needvalidation", checkIfAuthenticated, ... );
};

【问题讨论】:

    标签: node.js express-jwt


    【解决方案1】:

    发现最好的方法是使用谷歌的包google-auth-library

    【讨论】:

      猜你喜欢
      • 2022-06-14
      • 1970-01-01
      • 2023-04-03
      • 2013-06-30
      • 2020-08-14
      • 2020-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-13
      相关资源
      最近更新 更多