@yrneh_jang/ldapjs
v3.1.1
Published
LDAP client API with Cloudflare Workers support
Readme
@yrneh_jang/ldapjs
LDAP client for Node.js and Cloudflare Workers.
Fork of ldapjs/node-ldapjs with Cloudflare Workers support.
Changes from upstream
- Server removed:
createServer(),Server,persistentSearchare not included. This is a client-only package. - Cloudflare Workers support: Socket layer is automatically detected at runtime. Uses
cloudflare:socketsin CF Workers,net/tlsin Node.js. @yrneh_jang/asn1: Fork of@ldapjs/asn1wherefsis lazy-loaded so the module loads without error in CF Workers.
Installation
npm install @yrneh_jang/ldapjsUsage
Node.js
const ldap = require('@yrneh_jang/ldapjs')
const client = ldap.createClient({
url: ['ldap://127.0.0.1:389']
})
client.bind('cn=admin,dc=example,dc=com', 'secret', (err) => {
if (err) throw err
client.search('dc=example,dc=com', { filter: '(objectclass=*)' }, (err, res) => {
res.on('searchEntry', (entry) => {
console.log(entry.pojo)
})
res.on('end', () => client.unbind())
})
})Cloudflare Workers
Add the following to your wrangler.toml:
compatibility_flags = ["nodejs_compat"]Then use the same API as Node.js:
import ldap from '@yrneh_jang/ldapjs'
export default {
async fetch(request, env) {
const client = ldap.createClient({
url: ['ldap://your-ldap-server:389']
})
await new Promise((resolve, reject) => {
client.bind('cn=admin,dc=example,dc=com', 'secret', (err) => {
if (err) return reject(err)
resolve()
})
})
// ... perform LDAP operations
client.unbind()
return new Response('ok')
}
}API
Refer to the original ldapjs documentation for the full client API.
Server-related APIs (createServer, Server, persistentSearch) are not available in this package.
License
MIT
