我在我的 Web 应用程序中使用 passport-ldapauth npm 进行 LDAP / AD 身份验证,但我总是得到“无效的用户名/密码”,尽管我确信用户名和密码是正确的。这是我的代码
var express = require('express')
var app = express();
var bodyParser = require('body-parser');
var passport = require('passport');
var LdapStrategy = require('passport-ldapauth');
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With,
Content-Type, Accept");
next();
});
var OPTS = {
server: {
"url": "ldap://ip-address:389",
"bindDN": "cn=admin-username,dc=dcname,dc=com",
"bindCredentials": "admin-password",
"searchBase": "dc=dcname,dc=lan",
"searchFilter": "(sAMAccountName={username})",//I have tried (uid={{username}}) also.
},
passReqToCallback : true
};
passport.use(new LdapStrategy(OPTS));
app.post('/api/login', function(req, res, next) {
passport.authenticate('ldapauth', {session: true}, function(err, user, info)
{
console.log("err: " + err); //returns null
console.log("user: " + user);//returns false
console.log("info: " + JSON.stringify(info));//returns {"message":"Invalid username/password"}
if (err) {
return next(err); // will generate a 500 error
}
// Generate a JSON response reflecting authentication status
if (! user) {
return res.send({ success : false, message : 'authentication failed'
});
}
return res.send({ success : true, message : 'authentication succeeded'
});
})(req, res, next);
});
app.listen(3000, function() {
console.log('Listening on port 3000...')
});
请帮帮我。