---
title: LDAP
project: Total.js V4
version: 0.0.99
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/total-js-v4/0-0-99/reference/ldap/
updated: 2026-11-18T16:57:44.579Z
---

# LDAP

> LDAP() and its options.

## API

### LDAP(opt, [callback])

Type: `method`

Reads persons, groups or one user profile from an LDAP server (for example Active Directory).

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `opt.ldap` | `Object` | yes |  | `{ host: String, port: Number }` of the server. The port defaults to `389`. |
| `opt.user` | `String` | yes |  | The DN or user name used to bind. |
| `opt.password` | `String` | yes |  | The password used to bind. |
| `opt.type` | `String` | yes |  | `person`, `group` or `profile` (searched as `objectClass`). |
| `opt.dn` | `String` | no |  | The base DN of the search, for example `OU=Users,DC=company,DC=local`. |
| `opt.login` | `String` | no |  | The `sAMAccountName` of the user, required for the `profile` type. |
| `opt.noauth` | `Boolean` | no | `false` | Skips the bind and searches anonymously. |
| `callback` | `Function(err, response)` | no |  | 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.

Example: Read all groups
```js
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);
});
```

Example: Load one profile with a Promise
```js
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');
```
