Last active
August 24, 2016 05:13
-
-
Save yellowred/d55da0aa3ac3552c8d252019d351f7d6 to your computer and use it in GitHub Desktop.
add user to LDAP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let addUser = (userId, givenName, familyName, password) => { | |
return new Promise((resolve, reject) => { | |
// 1 | |
const ldapClient = ldapjs.createClient(ldapOptions); | |
// 2 | |
ldapClient.bind( | |
ldapConfig.pwdUser, | |
ldapConfig.pwdUserPassword, | |
(err) => { | |
if (err) return reject(err); | |
let newUser = { | |
givenName: 'none', | |
uid: userId, | |
givenName: givenName, | |
familyName: familyName, | |
cn: userId, | |
userPassword: password, | |
objectClass: ["person", "organizationalPerson", "inetOrgPerson"], | |
pwdPolicySubentry: ldapConfig.pwdPolicySubentry | |
}; | |
// 3 | |
ldapClient.add( | |
'cn=' + userId + ',' + ldapConfig.domain, | |
newUser, | |
(err, response) => { | |
if (err) return reject(err); | |
return resolve(response); | |
} | |
); | |
} | |
); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment