ldapts-search
TypeScript icon, indicating that this package has built-in type declarations

2.1.5 • Public • Published

ldapts-search

Utility to help search through active directory.

Definition:

class LdapSearch<Result> {
  constructor(params: {
    host: string;
    port: number;
    dn: string;
    password: string;
    searchBase: string;
    attributes?: string[];
  });
  match: (filter: string, sizeLimit?: number | undefined) => Promise<Result[]>;
}

Example usage:

type Result = {
  sAMAccountName: string;
  name: string;
  dn: string;
};

const ldapSearch = new LdapSearch<Result>({
  dn: "dn=test",
  host: "0.0.0.0",
  port: 1234,
  password: "password",
  searchBase: "dn=some,cn=searchbase",
  attributes: [
    "sAMAccountName",
    "name",
    "dn"
  ]
});

export function searchActiveDirectory(name: string): ActiveDirectoryRecord[] {
  return await ldapSearch.match(`(&(objectClass=Person)(sAMAccountName=${name}))`); // returns Result[]
}

Package Sidebar

Install

npm i ldapts-search

Weekly Downloads

57

Version

2.1.5

License

MIT

Unpacked Size

11.3 kB

Total Files

11

Last publish

Collaborators

  • hwkd