Socket
Socket
Sign inDemoInstall

kth-node-ldap

Package Overview
Dependencies
Maintainers
7
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kth-node-ldap - npm Package Compare versions

Comparing version 4.0.11 to 5.0.0

lib/index.js

61

package.json

@@ -1,1 +0,60 @@

{"name": "kth-node-ldap", "version": "4.0.11", "description": "Adds a Promise-based API on top of ldapjs as well as a filter builder.", "main": "index.js", "automaticPublish": "true", "scripts": {"test:mocha": "mocha tests/__mocha_tests__/** --exit", "test": "mocha tests/__mocha_tests__/** --exit && jest", "test:jest": "mocha tests/__mocha_tests__/** --exit && jest", "test:watch": "mocha tests/__mocha_tests__/** --exit && jest --watch", "build": "./build.sh", "lint": "eslint \"**/*.{js,jsx}\" --quiet", "lint-v": "eslint \"**/*.{js,jsx}\" ", "prepare": "bash -c 'if [ -f ./node_modules/.bin/husky ]; then husky install; fi'"}, "repository": {"type": "git", "url": "https://github.com/KTH/kth-node-ldap.git"}, "author": {"name": "KTH", "email": "infosys@kth.se", "url": "https://github.com/KTH"}, "keywords": ["ldap", "ldapjs", "promise", "filter"], "license": "MIT", "dependencies": {"async": "^3.2.4", "ldapjs": "^2.3.3", "ldapts": "^2.12.0"}, "peerDependencies": {"@kth/log": "^4.0.5"}, "devDependencies": {"@kth/eslint-config-kth": "^3.0.10", "@kth/log": "^4.0.5", "chai": "^4.3.6", "eslint": "^8.20.0", "husky": "^7.0.4", "jest": "^27.5.1", "mocha": "^9.2.2", "mockery": "^2.1.0", "prettier": "^2.7.1", "pretty-quick": "3.1.3"}, "prettier": {"arrowParens": "avoid", "printWidth": 120, "semi": false, "singleQuote": true, "trailingComma": "es5"}, "se.kth.automaticPublish": "true", "se.kth.gitBranch": "refs/heads/main", "se.kth.gitCommit": "fc4cc6a", "se.kth.buildDate": "2023-08-01 12:54:54"}
{
"name": "kth-node-ldap",
"version": "5.0.0",
"description": "Adds a Promise-based API on top of ldapjs as well as a filter builder.",
"main": "lib/index.js",
"files": [
"lib"
],
"scripts": {
"test:mocha": "mocha tests/__mocha_tests__/** --exit",
"test": "mocha tests/__mocha_tests__/** --exit && jest",
"test:jest": "jest",
"test:watch": "mocha tests/__mocha_tests__/** --exit && jest --watch",
"build": "./build.sh",
"lint": "eslint \"**/*.{js,jsx}\" --quiet",
"lint-v": "eslint \"**/*.{js,jsx}\" ",
"prepare": "bash -c 'if [ -f ./node_modules/.bin/husky ]; then husky install; fi'"
},
"repository": {
"type": "git",
"url": "https://github.com/KTH/kth-node-ldap.git"
},
"author": {
"name": "KTH",
"email": "infosys@kth.se",
"url": "https://github.com/KTH"
},
"keywords": [
"ldap",
"ldapjs",
"promise",
"filter"
],
"license": "MIT",
"dependencies": {
"async": "^3.2.4",
"ldapts": "^6.0.0"
},
"peerDependencies": {
"@kth/log": "^4.0.5"
},
"devDependencies": {
"@kth/eslint-config-kth": "^3.0.14",
"@kth/log": "^4.0.7",
"chai": "^4.3.8",
"eslint": "^8.48.0",
"husky": "^7.0.4",
"jest": "^27.5.1",
"mocha": "^9.2.2",
"prettier": "^2.8.8",
"pretty-quick": "3.1.3"
},
"prettier": {
"arrowParens": "avoid",
"printWidth": 120,
"semi": false,
"singleQuote": true,
"trailingComma": "es5"
}
}

97

README.md
# kth-node-ldap
Convenience library on top of the [ldapjs][ldapjs] client.
[ldapjs]: http://ldapjs.org/client.html
Convenience library on top of the [ldapts](https://www.npmjs.com/package/ldapts) client.
And now an alternative solution with ldapts is available. Set USE_LDAPTS environment variable and follow the code example for ldapts.
[ldapts]: github.com/ldapts/ldapts#readme
Note though that ldapts solution does not seem to return paged results. If you can assume that the result set might be large please do not use this or adapt your query so the result set is manageable.
## Code Example
It's highly recommended that you use [co][co] with this library.
[co]: https://www.npmjs.com/package/co
```javascript
var ldap = require('kth-node-ldap')
var co = require('co')
var client = ldap.createClient({
// same configuration as the usual ldapjs client
url: 'ldaps://ldap.example.com',
bindDN: 'user@ldap.example.com',
bindCredentials: 'secret',
})
// you can access the ldapjs client through client._client
// the library comes with helpers to build ldap filters:
var F = ldap.filters
var filter
// 1. match all entries with this exact memberOf value
filter = F.eq('memberOf', 'OU=users,DC=ldap,DC=example,DC=com')
// 2. or match all entries with a givenName starting with 'a', 'b', or 'c'
filter = F.orAll('givenName', ['a*', 'b*', 'c*'])
// 3. combine for more complex filters
filter = F.ne('givenName', 'f*').and(F.eq('familyName', 'g*'))
co(function* () {
var res = yield client.search('DC=ldap,DC=example,DC=com', {
scope: 'sub',
attributes: ['givenName', 'familyName', 'updatedOn'],
filter: filter,
paged: {
pageSize: 250,
// pagePause will be forced to true
// otherwise this library will not work
pagePause: true,
},
})
// access the ldapjs search result through res._res
// res.each() will handle paging and more
// all that's required is a function which returns a Promise
// (co.wrap() does this for us)
yield res.each(
co.wrap(function* (entry) {
// do something with entry
var user = {
givenName: entry.object.givenName,
familyName: entry.object.familyName,
// this library also provides a helper to convert dates
// assuming updatedOn is a lexical utc date (e.g. '20160921123456.0Z')
updatedOn: ldap.utils.toDate(entry.object.updatedOn),
}
// e.g. yield _saveToDb(user)
// NOTE: if you do a bulk insert here, make sure you execute
// the bulk every so often in case the search result contains
// thousands of entries...
})
)
client.close()
}).catch(function (err) {
console.error(err)
process.exit(1)
})
```
## Code Example LDAPTS
```
USE_LDAPTS=true
```
How to create client connection object and re-export relevant methods. In this example the file is named ldapImportClient.js

@@ -116,3 +32,2 @@

ldapSearchOne: searchOne,
useLdapTs: config.useLdapTs === 'true',
}

@@ -124,6 +39,3 @@ ```

```javascript
const { ldapClient, ldapSearch, ldapSearchOne, useLdapTs } = require('./ldapImportClient')
...
// If the feature flag should be used,
// wrap the usage with if (useLdapTs) {...}
const { ldapClient, ldapSearch, ldapSearchOne } = require('./ldapImportClient')

@@ -142,3 +54,3 @@ // Get all users changed since 2020-03-01

for (const user of usersArray) {
// Do what you have to do..
// Do what you have to do..
}

@@ -162,8 +74,5 @@ } catch (err) {

// Do what you have to do..
} catch (err) {
log.error('Could not query LDAP ', { err: e })
}
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc