# easy-ldap-login

> easy-ldap-login allows you to easily authenticate users on LDAP server and check if they are in a specific group

Latest version **0.2.0** (published 2025-04-10) · GPL-3.0-or-later license · 0 weekly downloads

## Install

```sh
npm install easy-ldap-login
pnpm add easy-ldap-login
yarn add easy-ldap-login
bun add easy-ldap-login
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2025-04-10 |
| First published | 2022-11-17 |
| Weekly downloads | 0 |
| License | GPL-3.0-or-later |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 60.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | angy91m |
| Maintainers | angy91m |
| Keywords | ldap, login, authentication, authenticate, authorization, authorize, ldapjs, wrapper |

## Links

- npm: https://www.npmjs.com/package/easy-ldap-login
- Repository: https://github.com/angy91m/easy-ldap-login
- Homepage: https://github.com/angy91m/easy-ldap-login#readme
- Issues: https://github.com/angy91m/easy-ldap-login/issues
- npm.io page: https://npm.io/package/easy-ldap-login

## Dependencies (2)

- [ldapjs](https://npm.io/package/ldapjs.md) ^3.0.2
- [is-ready-tcp](https://npm.io/package/is-ready-tcp.md) ^1.0.3

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 0.2.0 (latest) — 2025-04-10
- 0.1.9 — 2025-04-10
- 0.1.8 — 2023-07-07
- 0.1.7 — 2023-06-05
- 0.1.6 — 2023-05-19
- 0.1.5 — 2023-04-18
- 0.1.4 — 2023-04-06
- 0.1.3 — 2023-04-06
- 0.1.2 — 2023-03-25
- 0.1.1 — 2022-11-21
- 0.1.0 — 2022-11-17
- 0.0.9 — 2022-11-17

## README

# easy-ldap-login

easy-ldap-login is a wrapper of [ldapjs](https://www.npmjs.com/package/ldapjs) package that allows you to easily authenticate users on LDAP server and check if they are in a specific group.

## Installation

```bash
npm i easy-ldap-login
```

## Usage

```javascript
const LDAPLogin = require( 'easy-ldap-login' );
const ldapLogin = new LDAPLogin( 'ldap://myldap01.server.com', 'dc=domain,dc=com', { searchGroups: 'team_marketing', userSearchAttributes: ['givenName'] } );
ldapLogin.auth( 'userName', 'password' )
.then( userAttrs => console.log( `Hello ${userAttrs.givenName}!` ) )
.catch( () => console.log( 'Wrong credentials' ) );
```

## Methods

### `LDAPLogin.constructor`
```javascript
new LDAPLogin( serverUrls: String | Array, dcString: String [, options: Object = {} ] );
```

#### Parameters

* `serverUrls` Required - URL of the ldap server as `String` or an `Array` of URL Strings for round-robin
* `dcString` Required - `String` that identifies Domain Component
* `options` Optional - Module options as an `Object` with some properties:
  * `usersOu` Optional - `String` that identifies Organization Unit base for Users (Default: `'ou=users'`)
  * `userAttribute` Optional - `String` that identifies ID attribute for Users (Default: `'uid'`)
  * `groupsOu` Optional - `String` that identifies Organization Unit base for Groups (Default: `'ou=groups'`)
  * `groupMemberAttribute` Optional - `String` that identifies Group attribute to use for searching its members (Default: `'member'`)
  * `searchGroups` Optional - It can be one of these:
    * `String` that identifies Common Name of Group that User must have
    * `Object` with properties:
      * `cn` Required - `String` that identifies Common Name of the Group that User must have
      * `ou` Required - `String` that identifies Organization Unit base string of the Group
      * `userAttribute` Optional - `String` that identifies ID attribute for Users in the Group
      * `groupMemberAttribute` Optional - `String` that identifies Group attribute to use for searching its members
    * `Array` of the previous data for multiple groups
  * `userSearchAttributes` Optional - `Array` of `Strings` that indentify user attributes you want to retrieve
  * `tlsOptions` Optional - `Object` options passed to TLS connection layer when connecting via `ldaps://` (See: [TLS](https://nodejs.org/api/tls.html#tlsconnectoptions-callback) for node.js)
    * `caCertPath` Optional - `String` path of CA Cert File
    * `certPath` Optional - `String` path of Cert File

#### Return

An instance of `LDAPLogin`

### `LDAPLogin.auth`
```javascript
ldapLogin.auth( userName: String, password: String [, options: Object = {} ] );
```

#### Parameters

* `userName` Required - User's userName
* `password` Required - User's password
* `options` Optional - Module options as an `Object` with some properties:
  * `serverUrls` Optional - URL of the ldap server as `String` or an `Array` of URL Strings for multiple attempts
  * `usersOu` Optional - `String` that identifies Organization Unit base for Users (Default: `'ou=users'`)
  * `userAttribute` Optional - `String` that identifies ID attribute for Users (Default: `'uid'`)
  * `groupsOu` Optional - `String` that identifies Organization Unit base for Groups (Default: `'ou=groups'`)
  * `groupMemberAttribute` Optional - `String` that identifies Group attribute to use for searching its members (Default: `'member'`)
  * `searchGroups` Optional - It can be one of these:
    * `String` that identifies Common Name of Group that User must have
    * `Object` with properties:
      * `cn` Required - `String` that identifies Common Name of the Group that User must have
      * `ou` Required - `String` that identifies Organization Unit base string of the Group
      * `userAttribute` Optional - `String` that identifies ID attribute for Users in the Group
      * `groupMemberAttribute` Optional - `String` that identifies Group attribute to use for searching its members
    * `Array` of the previous data for multiple groups
  * `userSearchAttributes` Optional - `Array` of `Strings` that indentify user attributes you want to retrieve
  * `tlsOptions` Optional - `Object` options passed to TLS connection layer when connecting via `ldaps://` (See: [TLS](https://nodejs.org/api/tls.html#tlsconnectoptions-callback) for node.js)
    * `caCertPath` Optional - `String` path of CA Cert File
    * `certPath` Optional - `String` path of Cert File

#### Return

A promise that resolve if user correctly logged or reject error

---
_Source: https://npm.io/package/easy-ldap-login · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
