I cant to connect to my Windows server. I'm trying but I don't understand what I'm doing incorrect.
This is not my code, I can't understand manual for ldapjs and I would be grateful for help.
const ldap = require('ldapjs');
const client = ldap.createClient({
url: 'ldap://local.domain.pl/',
});
const opts = {
filter: '(&(cn=*))',
scope: 'sub',
// This attribute list is what broke your solution
attributes:['SamAccountName','dn']
};
console.log('--- going to try to connect user ---');
const username = 'username@domain.pl';
const password = 'pass';
try {
client.bind(username, password, function (error) { //first need to bind
console.log(client.url);
if (error) {
console.log(error.message);
client.unbind(function (error) {
if (error) {
console.log(error.message);
} else {
console.log('client disconnected');
}
});
} else {
console.log('connected');
client.search('ou=users, ou=compton, dc=batman, dc=com', opts, function (error, search) {
console.log('Searching.....');
search.on('searchEntry', function (entry) {
if (entry.object) {
console.log('entry: %j ' + JSON.stringify(entry.object));
}
client.unbind(function (error) {
if (error) {
console.log(error.message);
} else {
console.log('client disconnected');
}
});
});
search.on('error', function (error) {
console.error('error: ' + error.message);
client.unbind(function (error) {
if (error) {
console.log(error.message);
} else {
console.log('client disconnected');
}
});
});
}
);
}
})
}
catch(error){
console.log(error);
client.unbind(function(error) {if(error){console.log(error.message);} else{console.log('client disconnected');}});
}
And answer:
--- going to try to connect user ---
undefined
Invalid Credentials
client disconnected