Search code examples
node.jsexpress-jwt

How would I decode info from idToken using express-Jwt?


My application using Google's Authentication and the browser sends idToken to my API server. I use checkIfAuthenticated to validate the idToken, once validated ok, need to decode/extract info from it. But I can't figure out how to decode/extract.

Here is how it's validated and routing:

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, ... );
};

Solution

  • Found out the best way is to use Google's package google-auth-library