Modules@robinpath/ldap
ldap

@robinpath/ldap

0.1.5Node.jsPublic

LDAP client module for interacting with LDAP directories. Supports connecting, binding, searching, adding, modifying, and deleting entries. Includes convenience functions for user authentication, user lookup, and group membership queries.

LDAP

LDAP client module for interacting with LDAP directories. Supports connecting, binding, searching, adding, modifying, and deleting entries. Includes convenience functions for user authentication, user lookup, and group membership queries.

Package: @robinpath/ldap | Category: Utility | Type: Utility

Authentication

ldap.connect "your-credentials"

Call this once at the start of your script before using any other function. Credentials persist for the duration of the script execution.

Use Cases

Use the ldap module when you need to:

  • Search for entries in the LDAP directory -- Use ldap.search to perform this operation
  • Authenticate (bind) to the LDAP server with a DN and password -- Use ldap.bind to perform this operation
  • Unbind and disconnect from the LDAP server -- Use ldap.unbind to perform this operation
  • Add a new entry to the LDAP directory -- Use ldap.add to perform this operation
  • Modify an existing LDAP entry's attributes -- Use ldap.modify to perform this operation

Quick Reference

FunctionDescriptionReturns
connectCreate and connect an LDAP client to a serverobject
searchSearch for entries in the LDAP directoryobject
bindAuthenticate (bind) to the LDAP server with a DN and passwordobject
unbindUnbind and disconnect from the LDAP serverobject
addAdd a new entry to the LDAP directoryobject
modifyModify an existing LDAP entry's attributesobject
delDelete an entry from the LDAP directoryobject
compareCompare an attribute value against an LDAP entryobject
modifyDNRename an LDAP entry by changing its DNobject
findUserConvenience function to search for a user by usernameobject
authenticateAuthenticate a user by searching for their DN and then binding with their passwordobject
groupsGet all groups that a user belongs toobject
closeForcefully close the LDAP client connection and clean up resourcesobject
isConnectedCheck if the LDAP client is currently connectedobject

Functions

connect

Create and connect an LDAP client to a server

Module: ldap | Returns: object -- API response.

ldap.connect
ParameterTypeRequiredDescription
idstringNoClient identifier
urlstringNoLDAP server URL (e.g. ldap://localhost:389)
optionsobjectNoAdditional ldapjs client options

search

Search for entries in the LDAP directory

Module: ldap | Returns: object -- API response.

ldap.search
ParameterTypeRequiredDescription
idstringNoClient identifier
baseDNstringNoBase DN to search from
optionsobjectNoSearch options (filter, scope, attributes, etc.)

bind

Authenticate (bind) to the LDAP server with a DN and password

Module: ldap | Returns: object -- API response.

ldap.bind
ParameterTypeRequiredDescription
idstringNoClient identifier
dnstringNoDistinguished name to bind as
passwordstringNoPassword for authentication

unbind

Unbind and disconnect from the LDAP server

Module: ldap | Returns: object -- API response.

ldap.unbind
ParameterTypeRequiredDescription
idstringNoClient identifier

add

Add a new entry to the LDAP directory

Module: ldap | Returns: object -- API response.

ldap.add
ParameterTypeRequiredDescription
idstringNoClient identifier
dnstringNoDistinguished name for the new entry
entryobjectNoEntry attributes as key-value pairs

modify

Modify an existing LDAP entry's attributes

Module: ldap | Returns: object -- API response.

ldap.modify
ParameterTypeRequiredDescription
idstringNoClient identifier
dnstringNoDN of the entry to modify
changesarrayNoArray of changes with operation (add/delete/replace) and modification

del

Delete an entry from the LDAP directory

Module: ldap | Returns: object -- API response.

ldap.del
ParameterTypeRequiredDescription
idstringNoClient identifier
dnstringNoDN of the entry to delete

compare

Compare an attribute value against an LDAP entry

Module: ldap | Returns: object -- API response.

ldap.compare
ParameterTypeRequiredDescription
idstringNoClient identifier
dnstringNoDN of the entry to compare
attributestringNoAttribute name to compare
valuestringNoValue to compare against

modifyDN

Rename an LDAP entry by changing its DN

Module: ldap | Returns: object -- API response.

ldap.modifyDN
ParameterTypeRequiredDescription
idstringNoClient identifier
dnstringNoCurrent DN of the entry
newDNstringNoNew DN for the entry

findUser

Convenience function to search for a user by username

Module: ldap | Returns: object -- API response.

ldap.findUser
ParameterTypeRequiredDescription
idstringNoClient identifier
baseDNstringNoBase DN to search from
usernamestringNoUsername to search for
usernameAttributestringNoLDAP attribute for username (default: uid)

authenticate

Authenticate a user by searching for their DN and then binding with their password

Module: ldap | Returns: object -- API response.

ldap.authenticate
ParameterTypeRequiredDescription
idstringNoClient identifier
baseDNstringNoBase DN to search from
usernamestringNoUsername to authenticate
passwordstringNoUser password
usernameAttributestringNoLDAP attribute for username (default: uid)

groups

Get all groups that a user belongs to

Module: ldap | Returns: object -- API response.

ldap.groups
ParameterTypeRequiredDescription
idstringNoClient identifier
baseDNstringNoBase DN to search groups from
userDNstringNoDN of the user to find groups for
groupAttributestringNoGroup membership attribute (default: member)

close

Forcefully close the LDAP client connection and clean up resources

Module: ldap | Returns: object -- API response.

ldap.close
ParameterTypeRequiredDescription
idstringNoClient identifier

isConnected

Check if the LDAP client is currently connected

Module: ldap | Returns: object -- API response.

ldap.isConnected
ParameterTypeRequiredDescription
idstringNoClient identifier

Error Handling

All functions throw on failure. Common errors:

ErrorCause
Base DN is required.Check the error message for details
DN is required for bind.Check the error message for details
Password is required for bind.Check the error message for details
DN is required.Check the error message for details
Entry object is required.Check the error message for details
Changes array is required.Check the error message for details
Attribute name is required.Check the error message for details
Value is required.Check the error message for details
@desc "Search and validate result"
do
  set $result as ldap.search
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. Create a new item with add

Create a new resource and capture the result.

set $result as ldap.add
print "Created: " + $result

2. Create and update workflow

Create an item and then update it.

@desc "Add and modify"
do
  set $created as ldap.add
  # Update the created item
  ldap.modify
enddo

3. Multi-step LDAP workflow

Chain multiple ldap operations together.

@desc "Connect, search, and more"
do
  set $r_connect as ldap.connect
  set $r_search as ldap.search
  set $r_bind as ldap.bind
  print "All operations complete"
enddo

4. Safe connect with validation

Check results before proceeding.

@desc "Connect and validate result"
do
  set $result as ldap.connect
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.5latest1 months ago
Install
$ robinpath add @robinpath/ldap

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.5
LicenseMIT
Unpacked Size12.1 KB
Versions1
Weekly Downloads22
Total Downloads22
Stars0
Last Publish1 months ago
Created1 months ago

Keywords

Category

utilities