Closed victornikitin closed 5 years ago
Hi @victornikitin,
You're almost there :)
You indeed should register two different passport strategies using passport.use
, but the key is to use two different strategy names. For instance:
function myUserCallback(user, done) {
// Do something cool with user, then call done()
}
passport.use('ldapauth', new LdapStrategy(options, myUserCallback));
passport.use('basic-ldapauth', new LdapStrategy(options, myUserCallback));
Then later in an express middleware (assuming you're using https://github.com/expressjs/express):
passport.authenticate('ldapauth', ...); // To use usernameField + passwordField authentication
passport.authenticate('basic-ldapauth', ...); // To use basic authentication
passport.authenticate(['ldapauth', 'basic-ldapauth'], ...); // To support both (passport will try all given strategies serially until one succeeds, or fail the authentication)
Cheers, David
Closing as @ddolcimascolo already answered, and this is really once again not an issue in this library but generic passport
usage question.
Is it possible to use common auth (with usernameField and passwordField options) and basic auth (with credentialsLookup options) in the same application?
As far as I understood, i should call
passport.use(...)
twice with different options. If I callpassport.authenticate("ldapauth")
in 2 different middlewares how passport can understand which authenticate method should be called in each one?