Spanish Total.js
English
Documentation For AI agents
Contents

LDAP

LDAP() and its options.

.md GitHub
On this page

API

method

LDAP(opt, [callback])

Reads persons, groups or one user profile from an LDAP server (for example Active Directory).
ParameterTypeDescription
opt.ldap Object { host: String, port: Number } of the server. The port defaults to 389.
opt.user String The DN or user name used to bind.
opt.password String The password used to bind.
opt.type String person, group or profile (searched as objectClass).
opt.dn? String The base DN of the search, for example OU=Users,DC=company,DC=local.
opt.login? String The sAMAccountName of the user, required for the profile type.
opt.noauth? Boolean Skips the bind and searches anonymously. Default: false
callback? Function(err, response) Receives an array of entries, or one object for profile.

Returns Promise Only when the callback is not used.

Opens a TCP connection to opt.ldap, binds with opt.user and opt.password (unless opt.noauth is true) and searches opt.dn (subtree scope) for entries with objectClass equal to opt.type.

The profile type searches for one person whose sAMAccountName equals opt.login and returns a single object (or null). When opt.dn is empty, the framework uses opt.user as the base DN and returns the profile of the bound user.

Each entry is an object with attribute names as keys. An attribute with more values becomes an array; objectGUID and objectSid are returned as hex strings. Without a callback the method returns a Promise. The changelog marks the method as experimental.

Read all groups
LDAP({ ldap: { host: '10.0.0.5' }, user: 'CN=reader,DC=company,DC=local', password: CONF.ldap_password, type: 'group', dn: 'DC=company,DC=local' }, function(err, groups) {
	if (err)
		return;
	for (var group of groups)
		console.log(group.cn, group.member);
});
Load one profile with a Promise
var user = await LDAP({ ldap: { host: '10.0.0.5', port: 389 }, user: 'reader@company.local', password: CONF.ldap_password, type: 'profile', dn: 'DC=company,DC=local', login: 'peter' });
console.log(user ? user.displayName : 'not found');
Made in Europe