Folks, I would appreciate if you could help me with below. Now if hardcode username and password in the code, I can log in. But with form submit it is always invalid credential error.
{ InvalidCredentialsError: 80090308: LdapErr: DSID-0C0903D9, comment: AcceptSecurityContext error, data 52e, v2580
`
var url="ldap://ldap.company.com:389";
var dn='DC=Company,DC=com';
var bindUser="user@mycompany.com";
var bindPass='ldappassword';
var password="mypassword";
var ldapres = null
var opts = {
scope: 'sub',
}
var client = ad.createClient({ "url":url , "bindDN": bindUser, "bindCredentials": bindPass });
app.post('/api/ldap/authenticate', function (req, res) {
ldapres=null;
var name=req.body.username;
password=req.body.password;
console.log('username: -'+name+'- pass: -'+password+"-");
opts.filter= "(&(objectClass=user)(sAMAccountName=" +name + "))",
client.search(dn, opts, function (err, result) {
console.log('inside search');
result.on('searchEntry', function (entry) {
ldapres = entry.raw
console.log(ldapres.dn);
})
result.on('end', function (result) {
if (!ldapres) {
console.log('Invalid username');
return res.send('Invalid username')
}
client.bind(ldapres.dn, password, function (err) {
if (err) {
console.log(err);
return res.send('Wrong password')
client.unbind();
}
else{
console.log('You are loggedin');
res.send('You are logged')
}
})
})
})
}); `
Appreciate your help.
via leo
No comments:
Post a Comment