Making Active Directory jQuery-easy.
AD is a Javascript implementation of common Active Directory tasks, built to be simple as possible.
Really simple.
You can use async / await:
(async()=>{try{awaitad.user().add({userName: 'jsmith'firstName: 'John',lastName: 'Smith',location: '/Users/Sales',password: 'J@vascr!pt1'});awaitad.group().add('Sales');awaitad.user('jsmith').addToGroup('Sales');}catch(err){// ...}})();Or stick with promises:
ad.user('agnes').changePassword('d0ntForgetThisTime')\
.then(()=>ad.user('crook').disable()).then(()=>ad.user('larry').move('Dungeon')).catch((err)=>{// ...});- Robust
user,groupandoumanipulation methods - High and low-level search methods
- Caching by default
- Fancy result filtering including column and value filtering, sorting and pagination
- Companion drop-in REST API
First, install the library:
npm i adyarn add adThen add this to index.js:
constAD=require('ad');// Your AD account should be a member// of the Administrators group.constad=newAD({url: "ldaps://127.0.0.1",user: "dthree@acme.co",pass: "howinsecure"});ad.user().get().then(users=>{console.log('Your users:',users);}).catch(err=>{console.log('Error getting users:',err);});Now run the file:
node index.jsAnd you're off to the races.
ad.user().get(filter)ad.user().add(options)ad.user(username).get(filter)ad.user(userName).exists()ad.user(userName).addToGroup(groupName)ad.user(userName).removeFromGroup(groupName)ad.user(userName).isMemberOf(groupName)ad.user(userName).authenticate(password)ad.user(userName).password(password)ad.user(userName).passwordNeverExpires()ad.user(userName).passwordExpires()ad.user(userName).enable()ad.user(userName).disable()ad.user(userName).move(location)ad.user(userName).unlock()ad.user(userName).remove()ad.user(userName).location()ad.group().get(filter)ad.group().add(options)ad.group(groupName).get(filter)ad.group(groupName).exists()ad.group(groupName).members()ad.group(groupName).addUser(userName)ad.group(groupName).removeUser(userName)ad.group(groupName).remove()ad.ou().get(filter)ad.ou().add(options)ad.ou(ouName).get()ad.ou(ouName).exists()ad.ou(ouName).remove()ad.other().get(filter)ad.all().get(filter)ad.find(searchString)ad.cache(boolean)ad.cacheTimeout(millis)Returns all user objects.
awaitad.user().get({fields: 'sAMAccountName'});// => ['jsmith', 'dthree', 'qix'];Creates a new user. Returns the created user object.
userName: String (required)pass: String (required)commonName: String (required)firstName: StringlastName: Stringemail: Stringtitle: Stringlocation: String
If not specified, the first and last name will be based on the commonName.
awaitad.user().add({userName: 'jsmith'commonName: 'John Smith',password: 'J@vascr!pt1'});// => {sAMAccountName: 'jsmith' ... }Returns a user object. If no user is matched, returns undefined.
awaitad.user('jsmith').get();// => {sAMAccountName: 'jsmith', email: 'jsmith@acme.co' ... }Returns a Boolean of whether the user account matched.
awaitad.user('lochness').exists();// => falseAdds a user to a security group.
awaitad.user('jsmith').addToGroup('Sales');// => {success: true}Removes a user from a security group.
awaitad.user('jsmith').removeFromGroup('Sales');// => {success: true}Returns a Boolean based on whether the user is a member of a group.
awaitad.user('jsmith').isMemberOf('Sales');// => trueAttempts to authenticate a user with a given password. Returns Boolean.
awaitad.user('jsmith').authenticate('J@vascript1#!');// => trueSets a user's password.
awaitad.user('jsmith').password('Wh-m@ksp@ssw-rdslIkethis');// => trueSets a user's to never expire.
awaitad.user('jsmith').passwordNeverExpires();// => {success: true}Unchecks the "Password never expires" box.
awaitad.user('jsmith').passwordExpires();// => {success: true}Enables a user.
awaitad.user('jsmith').enable();// => {success: true}Disables a user.
awaitad.user('jsmith').disable();// => {success: true}Unlocks a user who has been locked out by repeated failed login attempts.
awaitad.user('jsmith').unlock();// => {success: true}Just kidding. You can't lock an account. Try disabling it instead.
awaitad.user('jsmith').disable();// => {success: true}Moves a user to another directory, starting from the root of the domain.
awaitad.user('jsmith').move('Users/HR');// => {success: true}This is the equivalent of acme.co => Users (OU) => HR (OU). The new Distinguished Name (DN) would become CN=John Smith,OU=HR,OU=Users,DC=acme,DC=co.
To specify a folder that is not an Organizational Unit, prefix it with !:
awaitad.user('admin').move('!Builtin');// => {success: true}Returns a user's relative location, separated by /es.
awaitad.user('jsmith').location();// => 'Users/HR'Deletes a user. Are you sure you want to do this?
awaitad.user('jsmith').remove();// => {success: true}Returns all group objects.
awaitad.group().get();// => [{ ... }, { ... }];Creates a new group. Returns the created group object.
name: String (required)location: Stringdescription: String
awaitad.group().add({name: 'HR'location: '!Builtin',description: 'Human Resources users.'});// => {sAMAccountName: 'HR' ... }Returns a group object. If no group is matched, returns undefined.
awaitad.group('HR').get();// => {sAMAccountName: 'HR', description: 'Human...' ... }Returns a Boolean of whether the group account matched.
awaitad.group('Beastie Boys').exists();// => falseReturns a Array of the group members.
awaitad.group('HR').members();// => [{sAMAccountName: 'hrchief', mail: 'hrchief@acme.com', ...} ... ]Adds a user to a group.
awaitad.group('HR').addUser('bjones');// => {success: true}Removes a user from a group.
awaitad.group('HR').removeUser('bjones');// => {success: true}Deletes a group.
awaitad.group('HR').remove();// => {success: true}Returns all ou objects.
awaitad.ou().get();// => [{ ... }, { ... }];Creates a new Organizational Unit. Returns the created OU object.
name: String (required)location: Stringdescription: String
awaitad.ou().add({name: 'Sales'location: 'Users'description: 'Sales Users.'});// => {ou: 'Sales' ... }Returns an OU object. If no OU is matched, returns undefined.
awaitad.ou('Sales').get();// => {ou: 'Sales', description: 'Sales...' ... }Returns a Boolean of whether the OU exists.
awaitad.ou('Sales').exists();// => trueDeletes an Organizational Unit. As a note, if it has any children, this will not work.
awaitad.ou('Sales').remove();// => {success: true}Returns all objects that are not users or groups.
awaitad.other().get();// => [{ ... }, { ... }];Returns all objects in the Active Directory instance, grouping by users, groups and other.
awaitad.other().get();// => [users: [...], groups: [...], other: [...]];Returns a raw search of the entire Active Directory.
awaitad.search('CN=Da*');// => [{...}, {...}];Enables or disables caching. Defaults to true.
ad.cache(false);Sets the amount of milliseconds before a cached item expires. Defaults to ten minutes. Chainable to ad.cache.
ad.cache(true).cacheTimeout(60000);Active Directory / LDAP can be hard. Some of us are stuck with it.
Should you really have to know that cn stands for Common Name (or was it Canonical) in order to use it? Or that sn is a surname*? I dislike systems that require detailed knowledge of their dirty laundry to do anything with them.
So this was a selfish project, really.
Made with <3 by dthree.
*last name
MIT