Skip to content

Instantly share code, notes, and snippets.

@davistran86
Forked from pvencill/LDAPjs New User
Created December 28, 2019 09:37
Show Gist options
  • Save davistran86/5ad7307fdbf761a36a72b9c7e7beacf2 to your computer and use it in GitHub Desktop.
Save davistran86/5ad7307fdbf761a36a72b9c7e7beacf2 to your computer and use it in GitHub Desktop.
Creating a new user in LDAPjs; complete example.
var ldap = require('ldapjs');
var ssha = require('node-ssha256');
var BASE = 'ou=Users,dc=example,dc=org';
// default port for ldaps
var URL = 'ldaps://ldap.example.org/:636';
// user and pass are for existing user with rights to add a user
function myLDAPBind(user, pass, callback) {
var client = ldap.createClient({
url: URL
});
var newDN = "cn=new guy,ou=Users,dc=example,dc=org";
var newUser = {
cn: 'new guy',
sn: 'guy',
uid: 'nguy',
mail: '[email protected]',
objectClass: 'inetOrgPerson',
userPassword: ssha.create('s00prs3cr3+')
}
client.bind(user,pass,function(err){
client.add(newDN, newUser, callback);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment