Browse docs

Active Directory integration in Node.js

The Active Directory-specific attributes and settings you'll need when pointing ldapjs at AD.

On this page

Everything in the previous pages works against Active Directory, but AD has a handful of specifics worth knowing before you connect to it. The full conceptual background lives in Active Directory — this page focuses on what changes in your ldapjs code.

Use the right base DN

An Active Directory base DN is derived from the domain name, not chosen freely. For a domain named corp.example.com, the base DN is dc=corp,dc=example,dc=com.

ts
const client = ldap.createClient({ url: "ldaps://dc1.corp.example.com:636" });
const baseDn = "DC=corp,DC=example,DC=com";
Login attribute: sAMAccountName vs userPrincipalName

Active Directory supports two common login identifiers:

  • sAMAccountName — the legacy, pre-Windows-2000 short username (e.g. jdoe).
  • userPrincipalName — the modern, email-shaped identifier (e.g. jdoe@corp.example.com).

Search for whichever one your login form actually collects:

ts
const filter = `(sAMAccountName=${escapeFilterValue(username)})`;
// or
const filter = `(userPrincipalName=${escapeFilterValue(username)})`;
objectGUID and objectSid are binary

Unlike most attributes, objectGUID (a unique identifier for the object) and objectSid (the security identifier) are returned as raw binary buffers, not strings. If you need to display or store them, decode them explicitly rather than treating them as UTF-8 text — mis-decoding these is a common source of subtle bugs when migrating code from other directories.

Disabled and locked-out accounts

Active Directory encodes account status inside the userAccountControl bitmask attribute rather than as separate boolean fields. A commonly checked bit is 0x2 (ACCOUNTDISABLE). Rather than parsing this bitmask by hand in every codebase, many teams instead rely on the bind itself failing with a decodable extended error — see Authentication in Active Directory.

Referral chasing

Large, multi-domain AD forests can return referrals — pointers to continue a search on a different domain controller. ldapjs does not chase referrals automatically by default; for most single-domain deployments this never comes up, but it's worth knowing if searches against a large forest come back incomplete.

What's next

Before shipping any of this, review Production security with ldapjs for TLS and credential-handling practices.