
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
A lightweight wrapper for ldapjs
for CRUD actions and some more.
Install it via npm
npm install ldapcrud
First of all, install and require ldapcrud
module in your script and create new instance of LDAPCRUD
class with your config;
const LDAPCRUD = require('ldapcrud');
let config = {
clientOptions: {
url: 'ldaps://your-ldap-url',
tlsOptions: {
rejectUnauthorized: false
}
},
baseDN: 'OU=Customers,DC=Company,DC=local',
userDN: 'CN=serviceadmin,OU=Customers,DC=Company,DC=local',
password: 'secret',
attributes: [
'sAMAccountName',
'mail',
'sn',
'givenName'
],
defaultFilter: '(mail=*@*)',
suffix: '@Company.local',
model: {
'sAMAccountName': 'ldap',
'mail': 'email',
'sn': 'name.last',
'givenName': 'name.first'
}
};
let ldap = new LDAPCRUD(config);
clientOptions
object - options for ldapjs client creation. See morebaseDN
string - DN where search users.userDN
string - Admin User DN, that can performs operations against the LDAP server.password
string - Admin User password.attributes
Array - Array of properties to selectdefaultFilter
string - LDAP Filter stringsuffix
string - User model suffixmodel
object - relation LDAP properties to your custom User model, where keys are LDAP properties and values are yours User model fields.Convert LDAP User model to yours format or vice versa.
model
param of config is required. Also you can use flatten
module, if
you have nested user object
let user = flatten({
name: {
first: 'John',
last: 'Doe'
},
email: 'johndoe@mail.com'
});
let ldapModel = ldap.convertModel(user, true);
// ldapModel === {
// sn: 'Doe',
// givenName: 'John',
// mail: 'johndoe@mail.com'
// }
Create LDAP client
ldap.createClient((err, client) => {
// Handle error and do something
});
LDAP Authentication
let dn = '(sAMAccountName=username)';
let pwd = 'secret';
ldap.authenticate(dn, pwd, (err, auth) => {
if (err) return console.error(err);
console.log('Authorize:', (auth) ? 'success' : 'failed');
});
Create entry in LDAP by provided entry properties.
displayName
, cn
, name
properties generetes from sn
and
givenName
.dn / distinguishedName
generetes by cn
, provided dn
property and
baseDN
property of configuserPrincipalName
concatenates from provided sAMAccountName
property
and suffix
property of configlet entry = {
sn: 'User',
givenName: 'Test',
sAMAccountName: 'testUser',
mail: 'testUser@mail.com',
};
ldap.create(entry, (err) => {
// Handle error and do something
});
Read entries in LDAP.
findUsers
is alias for read
ldap.read({
filter: '(sAMAccountName=username)'
}, (err, users) => {
// Handle error and do something
});
Update user
Change password in Active Directory
function encodePassword(password) {
return new Buffer('"' + password + '"', 'utf16le').toString();
}
let pwd = 'secret';
let attrs = [
{
type: 'replace',
attr: 'unicodePwd',
value: encodePassword(pwd)
},
{
type: 'replace',
attr: 'userAccountControl',
value: '66048'
}
];
ldap.update('(sAMAccountName=username)', attrs, (err) => {
// Handle error and do something
});
Delete user
ldap.delete('(sAMAccountName=username)', (err) => {
// Handle error and do something
});
Move user to other DN. Work in progress! Not tested!
FAQs
A lightweight wrapper for ldapjs for CRUD actions and some more
The npm package ldapcrud receives a total of 40 weekly downloads. As such, ldapcrud popularity was classified as not popular.
We found that ldapcrud demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.