我的应用程序使用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-auth-library