node-saml / passport-saml

SAML 2.0 authentication with Passport

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a way to test a provider configuration before call done() on MultiSamlStrategy?

jeff-pal opened this issue · comments

I'm looking for a way to check provider configuration before to call done() callback, since it does not throw exception directly into findProvider(). So I'm wondering, how can we test/check the provider configuration?

passport.use(
  new MultiSamlStrategy(
    {
      passReqToCallback: true,
      getSamlOptions: function (request, done) {
        findProvider(request, function (err, provider) {
          try {
            if (err) {
              return done(err);
            }

            const result = testConfig(provider.configuration);    <------------- Check provider configuration
            if(result.error) {
              // Do something...
            }

            return done(null, provider.configuration);
          } catch (e) {
            console.error(e.message);
          }
        });
      },
    },
    function (req, profile, done) {
      // for signon
      findByEmail(profile.email, function (err, user) {
        if (err) {
          return done(err);
        }
        return done(null, user);
      });
    },
  )
);

I'm not sure what you're asking here. findProvider() and findByEmail() are examples of functions you'd write yourself. So just write your own function to throw, or whatever other behavior you'd like.