Closed whittssg closed 8 years ago
Probably not the best at all but i changed a few things in the local passport login files to get it to work:
import passport from 'passport';
import {
Strategy as LocalStrategy
}
from 'passport-local';
var LdapAuth = require('ldapauth-fork');
function localAuthenticate(User, email, password, done) {
var ldap = new LdapAuth({
url: "LDAP://",
bindDn: "ldapuser",
bindCredentials: "ldappass",
searchBase: "DC=domain,DC=com",
searchFilter: "(sAMAccountName={{username}})",
cache: false
});
ldap.authenticate(email, password, function (err, ldapuser) {
if (err) {
console.log("LDAP Error: %s", err);
return done(null, false, {
message: 'The password or username is not correct.'
});
} else {
User.findOneAsync({
email: ldapuser.mail.toLowerCase()
})
.then(user => {
if (!user) {
user = new User({
name: ldapuser.givenName + " " + ldapuser.sn,
email: ldapuser.mail.toLowerCase(),
role: 'user',
username: ldapuser.sAMAccountName.toLowerCase(),
provider: 'local'
});
user.saveAsync()
.then(user => done(null, user))
.catch(err => done(err));
return done(null, user);
} else {
return done(null, user);
};
})
.catch(err => {
console.log("Error: ", err);
done(err)
});
}
});
}
export function setup(User, config) {
passport.use(new LocalStrategy({
usernameField: 'email',
passwordField: 'password' // this is the virtual field on the model
}, function (email, password, done) {
return localAuthenticate(User, email, password, done);
}));
}
Does this look OK? i am new to passport and javascript in general :)
Questions like this are better served on a question/answer site like Stack Overflow;
OK no problem, just thought you guys might have a sample hanging around. I will post it there.
If you get it working, feel free to submit it to the Wiki. I try to keep the issues section to bugs, feature requests, and questions specific to this project.
consider using the npm install https://www.npmjs.com/package/passport-ldapauth
Hello,
Does anyone have a LDAP login example for this generator?
I have used https://github.com/vesse/passport-ldapauth before but i cant seem to figure out how to integrate it into this generator.
Thanks,