panva / openid-client

OAuth 2 / OpenID Connect Client API for JavaScript Runtimes
MIT License
1.83k stars 392 forks source link

client must be an instance of openid-client Client #515

Closed corinz closed 2 years ago

corinz commented 2 years ago

Describe the bug Error says wrong type is passed, but type is confirmed.

To Reproduce Issuer and Client configuration: (inline or gist) - Don't forget to redact your secrets.

 createClient(obj){
    const { Issuer, Strategy } = require('openid-client');
    Issuer.discover(this.OIDC_PROVIDER_URL).then(
        function(oidcIssuer) {
        const oidcClient = new oidcIssuer.Client({
          client_id: obj.clientId,
          client_secret: 'NONE',
          redirect_uris: [obj.REDIRECT_URI],
          response_types: ['code'],
        });

        obj.passport.use('openid-client',
          new Strategy({ oidcClient, passReqToCallback: true }, (req, tokenSet, userinfo, done) => {
            if (this.DEBUG) console.log("tokenSet", tokenSet);
            if (this.DEBUG) console.log("userinfo", userinfo);
            req.session.tokenSet = tokenSet;  
            req.session.userinfo = userinfo;
            return done(null, tokenSet.claims());
          }));
        })
    }

Steps to reproduce the behaviour:

  1. Create an class with a constructor that calls the method above
  2. Execute

Expected behaviour Strategy created without issues/errors

Environment:

Additional context Add any other context about the problem here.

Thank you!

panva commented 2 years ago

Please see the docs. https://github.com/panva/node-openid-client/blob/v5.x/docs/README.md#strategy