auth0 / node-jwks-rsa

A library to retrieve RSA public keys from a JWKS (JSON Web Key Set) endpoint.
MIT License
837 stars 236 forks source link

cb is not a function #361

Closed N3evin closed 1 year ago

N3evin commented 1 year ago

I am trying to implement the it using the example provided in passport-demo

For my project I am trying to incorperate multiple authentication service such as google, facebook, Microsoft and auth0.

Below is my code, which I am using it together with Auth0.

require("dotenv").config();
const jwksRsa = require("jwks-rsa");
const ExtractJwt = require("passport-jwt").ExtractJwt;
const JwtStrategy = require("passport-jwt").Strategy;

module.exports = () => {
    const options = {
        jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
        issuer: process.env.AUTH0_DOMAIN,
        audience: "https://" + process.env.AUTH0_DOMAIN + "/api/v2/",
        secretOrKey: jwksRsa.passportJwtSecret({
            cache: true,
            rateLimit: true,
            jwksRequestsPerMinute: 5,
            jwksUri: `https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json`,
        }),
        algorithms: [ 'RS256' ]
    };

    return new JwtStrategy(options, function (req, jwt_payload, done){
        if (jwt_payload && jwt_payload.sub) {
            return done(null, jwt_payload);
        }

        return done(null, false);
    });
};

However, I keep receiving this error.

C:\Users\root\Documents\Git\demo\server\node_modules\jwks-rsa\src\integrations\passport.js:42
      return cb(null, null);
             ^

TypeError: cb is not a function
    at secretProvider (C:\Users\root\Documents\Git\demo\server\node_modules\jwks-rsa\src\integrations\passport.js:42:14)
    at module.exports [as verify] (C:\Users\root\Documents\Git\demo\server\node_modules\jsonwebtoken\verify.js:101:10)
    at module.exports [as JwtVerifier] (C:\Users\root\Documents\Git\demo\server\node_modules\passport-jwt\lib\verify_jwt.js:4:16)
    at C:\Users\root\Documents\Git\demo\server\node_modules\passport-jwt\lib\strategy.js:104:25
    at JwtStrategy._secretOrKeyProvider (C:\Users\root\Documents\Git\demo\server\node_modules\passport-jwt\lib\strategy.js:40:13)
    at JwtStrategy.authenticate (C:\Users\root\Documents\Git\demo\server\node_modules\passport-jwt\lib\strategy.js:99:10)
    at attempt (C:\Users\root\Documents\Git\demo\server\node_modules\passport\lib\middleware\authenticate.js:369:16)
    at strategy.fail (C:\Users\root\Documents\Git\demo\server\node_modules\passport\lib\middleware\authenticate.js:305:9)
    at Strategy.failWithLog (C:\Users\root\Documents\Git\demo\server\node_modules\passport-azure-ad\lib\bearerstrategy.js:599:15)
    at Strategy.jwtVerifyFunc [as jwtVerify] (C:\Users\root\Documents\Git\demo\server\node_modules\passport-azure-ad\lib\bearerstrategy.js:306:19)
N3evin commented 1 year ago

I had removed passport-azure-ad and gotten this follow error.

TypeError: cb is not a function
    at secretProvider (C:\Users\root\Documents\Git\demo\server\node_modules\jwks-rsa\src\integrations\passport.js:42:14)
    at module.exports [as verify] (C:\Users\root\Documents\Git\demo\server\node_modules\jsonwebtoken\verify.js:101:10)
    at module.exports [as JwtVerifier] (C:\Users\root\Documents\Git\demo\server\node_modules\passport-jwt\lib\verify_jwt.js:4:16)
    at C:\Users\root\Documents\Git\demo\server\node_modules\passport-jwt\lib\strategy.js:104:25
    at JwtStrategy._secretOrKeyProvider (C:\Users\root\Documents\Git\demo\server\node_modules\passport-jwt\lib\strategy.js:40:13)
    at JwtStrategy.authenticate (C:\Users\root\Documents\Git\demo\server\node_modules\passport-jwt\lib\strategy.js:99:10)
    at attempt (C:\Users\root\Documents\Git\demo\server\node_modules\passport\lib\middleware\authenticate.js:369:16)
    at authenticate (C:\Users\root\Documents\Git\demo\server\node_modules\passport\lib\middleware\authenticate.js:370:7)
    at Layer.handle [as handle_request] (C:\Users\root\Documents\Git\demo\server\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\root\Documents\Git\demo\server\node_modules\express\lib\router\route.js:144:13)
N3evin commented 1 year ago

All good :) The issue is my end with the verify callback function