问题描述
我的应用程序使用 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,... );
};
解决方法
发现最好的方法是使用 Google 的软件包 google-auth-library