0.1.8 • Published 2 years ago
easy-ldap-login v0.1.8
easy-ldap-login
easy-ldap-login is a wrapper of ldapjs package that allows you to easily authenticate users on LDAP server and check if they are in a specific group.
Installation
npm i easy-ldap-loginUsage
const LDAPLogin = require( 'easy-ldap-login' );
const ldapLogin = new LDAPLogin( 'ldap://myldap01.server.com', 'dc=domain,dc=com', { searchGroups: 'team_marketing', userSearchAttributes: ['givenName'] } );
ldapLogin.auth( 'userName', 'password' )
.then( userAttrs => console.log( `Hello ${userAttrs.givenName}!` ) )
.catch( () => console.log( 'Wrong credentials' ) );Methods
LDAPLogin.constructor
new LDAPLogin( serverUrls: String | Array, dcString: String [, options: Object = {} ] );Parameters
serverUrlsRequired - URL of the ldap server asStringor anArrayof URL Strings for round-robindcStringRequired -Stringthat identifies Domain ComponentoptionsOptional - Module options as anObjectwith some properties:usersOuOptional -Stringthat identifies Organization Unit base for Users (Default:'ou=users')userAttributeOptional -Stringthat identifies ID attribute for Users (Default:'uid')groupsOuOptional -Stringthat identifies Organization Unit base for Groups (Default:'ou=groups')groupMemberAttributeOptional -Stringthat identifies Group attribute to use for searching its members (Default:'member')searchGroupsOptional - It can be one of these:Stringthat identifies Common Name of Group that User must haveObjectwith properties:cnRequired -Stringthat identifies Common Name of the Group that User must haveouRequired -Stringthat identifies Organization Unit base string of the GroupuserAttributeOptional -Stringthat identifies ID attribute for Users in the GroupgroupMemberAttributeOptional -Stringthat identifies Group attribute to use for searching its members
Arrayof the previous data for multiple groups
userSearchAttributesOptional -ArrayofStringsthat indentify user attributes you want to retrievetlsOptionsOptional -Objectoptions passed to TLS connection layer when connecting vialdaps://(See: TLS for node.js)caCertPathOptional -Stringpath of CA Cert FilecertPathOptional -Stringpath of Cert File
Return
An instance of LDAPLogin
LDAPLogin.auth
ldapLogin.auth( userName: String, password: String [, options: Object = {} ] );Parameters
userNameRequired - User's userNamepasswordRequired - User's passwordoptionsOptional - Module options as anObjectwith some properties:serverUrlsOptional - URL of the ldap server asStringor anArrayof URL Strings for multiple attemptsusersOuOptional -Stringthat identifies Organization Unit base for Users (Default:'ou=users')userAttributeOptional -Stringthat identifies ID attribute for Users (Default:'uid')groupsOuOptional -Stringthat identifies Organization Unit base for Groups (Default:'ou=groups')groupMemberAttributeOptional -Stringthat identifies Group attribute to use for searching its members (Default:'member')searchGroupsOptional - It can be one of these:Stringthat identifies Common Name of Group that User must haveObjectwith properties:cnRequired -Stringthat identifies Common Name of the Group that User must haveouRequired -Stringthat identifies Organization Unit base string of the GroupuserAttributeOptional -Stringthat identifies ID attribute for Users in the GroupgroupMemberAttributeOptional -Stringthat identifies Group attribute to use for searching its members
Arrayof the previous data for multiple groups
userSearchAttributesOptional -ArrayofStringsthat indentify user attributes you want to retrievetlsOptionsOptional -Objectoptions passed to TLS connection layer when connecting vialdaps://(See: TLS for node.js)caCertPathOptional -Stringpath of CA Cert FilecertPathOptional -Stringpath of Cert File
Return
A promise that resolve if user correctly logged or reject error