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

# LDAP

> LDAP() e le sue opzioni.

## API

### LDAP(opt, [callback])

Type: `method`

Legge persone, gruppi o un profilo utente da un server LDAP (ad esempio Active Directory).

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `opt.ldap` | `Object` | yes |  | `{ host: String, port: Number }` del server. La porta predefinita è `389`. |
| `opt.user` | `String` | yes |  | Il DN o il nome utente usato per il bind. |
| `opt.password` | `String` | yes |  | La password usata per il bind. |
| `opt.type` | `String` | yes |  | `person`, `group` o `profile` (cercato come `objectClass`). |
| `opt.dn` | `String` | no |  | Il DN di base della ricerca, ad esempio `OU=Users,DC=company,DC=local`. |
| `opt.login` | `String` | no |  | Il `sAMAccountName` dell'utente, obbligatorio per il tipo `profile`. |
| `opt.noauth` | `Boolean` | no | `false` | Salta il bind ed effettua una ricerca anonima. |
| `callback` | `Function(err, response)` | no |  | Riceve un array di voci, oppure un oggetto per `profile`. |

Returns: `Promise` Solo quando la callback non viene usata.

Apre una connessione TCP verso `opt.ldap`, effettua il bind con `opt.user` e `opt.password` (a meno che `opt.noauth` non sia `true`) e cerca in `opt.dn` (ambito subtree) le voci con `objectClass` uguale a `opt.type`.

Il tipo `profile` cerca una `person` il cui `sAMAccountName` è uguale a `opt.login` e restituisce un singolo oggetto (oppure `null`). Quando `opt.dn` è vuoto, il framework usa `opt.user` come DN di base e restituisce il profilo dell'utente con cui è stato effettuato il bind.

Ogni voce è un oggetto con i nomi degli attributi come chiavi. Un attributo con più valori diventa un array; `objectGUID` e `objectSid` vengono restituiti come stringhe esadecimali. Senza callback il metodo restituisce una Promise. Il changelog indica il metodo come sperimentale.

Example: Leggere tutti i gruppi
```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: Caricare un profilo con una 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');
```
