---
title: LDAP
project: Total.js V5
version: 0.0.20
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/total-js-v5/0-0-20/reference/ldap/
updated: 2026-11-18T16:57:34.578Z
---

# LDAP

> LDAP() and its options.

## API

### LDAP(options, [callback])

Type: `method`

Searches an LDAP server (Active Directory) and returns users or groups.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `options` | `Object` | yes |  | The connection and the search, see below. |
| `callback` | `Function` | no |  | `function(err, response)`. Without it the function returns a promise. |

Returns: `Promise` With the response when no callback is given.

Binds to the server with `user` and `password` (a simple bind), runs one search and returns the entries. The connection is closed afterwards. The search is complete when the server stops sending data for 1.5 seconds.

| Option | Description |
| --- | --- |
| `ldap` | `{ host, port, secure, timeout }`. `port` defaults to `389`; `secure: true` connects with TLS; `timeout` limits the connection in ms |
| `user`, `password` | Credentials for the bind (a DN or, for Active Directory, also `user@domain`) |
| `dn` | Base DN of the search |
| `type` | `objectClass` to search for, such as `person` or `group`; `profile` searches one person by `login` |
| `login` | The `sAMAccountName` for `type: 'profile'` |
| `noauth` | `true` skips the bind |
| `attributes` | How to read attributes: `{ thumbnailPhoto: 'buffer' }`. Types: `string`, `number`, `date`, `buffer`, `binary` (also a buffer), `hex`, `base64`, `ascii`, `utf8`, in lower case |

The response is an array of objects, or one object (or `null`) for `type: 'profile'` and when `dn` is missing. Without `dn` the search uses `user` as the base DN, so you get the entry of the user that logged in. Values are strings, arrays of strings for several values, and hex strings for `objectGUID` and `objectSid`.

When the server refuses the bind (a wrong user or password), the error is the text of the server or, when the server sends no text, `LDAP bind error <code>` (`LDAP bind error 49` for invalid credentials). This error is a string, so the promise rejects with a string; the response is `null` for a profile and an empty array for a search. An invalid `ldap.host` gives the error `Invalid hostname`; the host is converted with `U.tohost()` before the connection.

Example: Groups
```js
var groups = await LDAP({
	ldap: { host: 'ad.example.com' },
	user: 'reader@example.com',
	password: CONF.ldap_password,
	dn: 'OU=Groups,DC=example,DC=com',
	type: 'group'
});
```

Example: One account
```js
LDAP({ ldap: { host: 'ad.example.com', port: 636, secure: true }, user: 'reader@example.com', password: CONF.ldap_password, dn: 'DC=example,DC=com', type: 'profile', login: 'peter' }, function(err, profile) {
	profile && console.log(profile.mail);
});
```
