Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Authelia | 16,449 | 1 | 18 hours ago | 34 | September 19, 2022 | 98 | apache-2.0 | Go | ||
The Single Sign-On Multi-Factor portal for web apps | ||||||||||
Errbit | 4,213 | 158 | 10 | a month ago | 7 | February 26, 2016 | 65 | mit | Ruby | |
The open source error catcher that's Airbrake API compliant | ||||||||||
Lldap | 2,546 | 7 days ago | 47 | gpl-3.0 | Rust | |||||
Light LDAP implementation | ||||||||||
Pac4j | 2,262 | 146 | 129 | a day ago | 96 | September 08, 2022 | apache-2.0 | Java | ||
Security engine for Java (authentication, authorization, multi frameworks): OAuth, CAS, SAML, OpenID Connect, LDAP, JWT... | ||||||||||
Glauth | 1,929 | 3 | 2 months ago | 20 | February 28, 2022 | 63 | mit | Go | ||
A lightweight LDAP server for development, home use, or CI | ||||||||||
Kanidm | 1,474 | 3 | a day ago | 9 | May 01, 2022 | 115 | mpl-2.0 | Rust | ||
Kanidm: A simple, secure and fast identity management platform | ||||||||||
Adldap2 Laravel | 910 | 99 | 16 | 25 days ago | 96 | November 12, 2020 | 107 | mit | PHP | |
LDAP Authentication & Management for Laravel | ||||||||||
Caddy Security | 789 | 2 months ago | 36 | June 20, 2022 | 95 | apache-2.0 | Go | |||
🔐 Authentication, Authorization, and Accounting (AAA) App and Plugin for Caddy v2. 💎 Implements Form-Based, Basic, Local, LDAP, OpenID Connect, OAuth 2.0 (Github, Google, Facebook, Okta, etc.), SAML Authentication. MFA/2FA with App Authenticators and Yubico. 💎 Authorization with JWT/PASETO tokens. 🔐 | ||||||||||
Maxkey | 781 | 3 days ago | 7 | apache-2.0 | Java | |||||
MaxKey SSO ,Leading-Edge IAM-IDaas(Identity and Access Management) Product. | ||||||||||
Yacy_webclient_authentication | 669 | 8 years ago | apache-2.0 | PHP | ||||||
Authentication layer for a YaCy webclient |
Make authentication with an LDAP server easy.
This library use ldapjs
as the underneath library. It has three modes of authentications:
Admin authenticate mode. If an admin user is provided, the library will login (ldap bind) with the admin user, then search for the user to be authenticated, get its DN (distinguish name), then use the user DN and password to login again. If every thing is ok, the user details will be returned.
Self authenticate mode. If the admin user is not provided, then the userDn
and userPassword
must be provided.
If any of userSearchBase
or usernameAttribute
is missing, then the lib simply does a login with
the userDn
and userPassword
(ldap bind), and returns true if succeeds.
Otherwise, the lib does a login with the userDn
and userPassword
(ldap bind),
then does a search on the user and return the user's details.
Verify user exists. If an verifyUserExists : true
is provided, the library will login (ldap bind) with the admin user,
then search for the user to be verified. If the user exists, user details will be returned (without verifying the user's password).
npm install ldap-authentication --save
An example on how to use with Passport is passport-ldap-example
Another simple library express-passport-ldap-mongoose provide turn key solution
let authenticated = await authenticate({
ldapOpts: { url: 'ldap://ldap.forumsys.com' },
userDn: 'uid=gauss,dc=example,dc=com',
userPassword: 'password',
})
let authenticated = await authenticate({
ldapOpts: { url: 'ldap://ldap.forumsys.com' },
userDn: 'uid=gauss,dc=example,dc=com',
userPassword: 'password',
userSearchBase: 'dc=example,dc=com',
usernameAttribute: 'uid',
username: 'gauss',
attributes: ['dn', 'sn', 'cn'],
})
let authenticated = await authenticate({
ldapOpts: { url: 'ldap://ldap.forumsys.com' },
userDn: 'uid=gauss,dc=example,dc=com',
verifyUserExists: true,
userSearchBase: 'dc=example,dc=com',
usernameAttribute: 'uid',
username: 'gauss',
})
let authenticated = await authenticate({
ldapOpts: { url: 'ldap://ldap.forumsys.com' },
userDn: 'uid=gauss,dc=example,dc=com',
userPassword: 'password',
userSearchBase: 'dc=example,dc=com',
usernameAttribute: 'uid',
username: 'gauss',
groupsSearchBase: 'dc=example,dc=com',
groupClass: 'groupOfUniqueNames',
groupMemberAttribute: 'uniqueMember',
// groupMemberUserAttribute: 'dn'
})
const { authenticate } = require('ldap-authentication')
async function auth() {
// auth with admin
let options = {
ldapOpts: {
url: 'ldap://ldap.forumsys.com',
// tlsOptions: { rejectUnauthorized: false }
},
adminDn: 'cn=read-only-admin,dc=example,dc=com',
adminPassword: 'password',
userPassword: 'password',
userSearchBase: 'dc=example,dc=com',
usernameAttribute: 'uid',
username: 'gauss',
// starttls: false
}
let user = await authenticate(options)
console.log(user)
// auth with regular user
options = {
ldapOpts: {
url: 'ldap://ldap.forumsys.com',
// tlsOptions: { rejectUnauthorized: false }
},
userDn: 'uid=einstein,dc=example,dc=com',
userPassword: 'password',
userSearchBase: 'dc=example,dc=com',
usernameAttribute: 'uid',
username: 'einstein',
// starttls: false
}
user = await authenticate(options)
console.log(user)
}
auth()
ldapOpts
: This is passed to ldapjs
client directly
url
: url of the ldap server. Example: ldap://ldap.forumsys.com
tlsOptions
: options to pass to node tls. Example: { rejectUnauthorized: false }
connectTimeout
: Int. Default: 5000
. Connect timeout in msadminDn
: The DN of the admistrator. Example: cn=read-only-admin,dc=example,dc=com
,adminPassword
: The password of the admin.userDn
: The DN of the user to be authenticated. This is only needed if adminDn
and adminPassword
are not provided.
Example: uid=gauss,dc=example,dc=com
userPassword
: The password of the userverifyUserExists
: if true
user existence will be verified without passworduserSearchBase
: The ldap base DN to search the user. Example: dc=example,dc=com
usernameAttribute
: The ldap search equality attribute name corresponding to the user's username.
It will be used with the value in username
to construct an ldap filter as ({attribute}={username})
to find the user and get user details in LDAP.
In self authenticate mode (userDn
and userPassword
are provided, but not adminDn
and adminPassword
),
if this value is not set, then authenticate will return true right after user bind succeed. No user details
from LDAP search will be performed and returned.
Example: uid
username
: The username to authenticate with. It is used together with the name in usernameAttribute
to construct an ldap filter as ({attribute}={username})
to find the user and get user details in LDAP. Example: some user input
attributes
: A list of attributes of a user details to be returned from the LDAP server.
If is set to []
or ommited, all details will be returned. Example: ['sn', 'cn']
starttls
: Boolean. Use STARTTLS
or notgroupsSearchBase
: if specified with groupClass, will serve as search base for authenticated user groupsgroupClass
: if specified with groupsSearchBase, will be used as objectClass in search filter for authenticated user groupsgroupMemberAttribute
: if specified with groupClass and groupsSearchBase, will be used as member name (if not specified this defaults to member
) in search filter for authenticated user groupsgroupMemberUserAttribute
: if specified with groupClass and groupsSearchBase, will be used as the attribute on the user object (if not specified this defaults to dn
) in search filter for authenticated user groupsThe user object if authenticate()
is success.
In version 2, The user object has a raw
field that has the raw data from the LDAP/AD server. It can be used to access buffer objects (profile pics for example).
Buffer data can now be accessed by user.raw.profilePhoto
, etc, instead of user.profilePhoto
.
In version 3, the raw
field is no longer used. Instead, append ;binary
to the attributes you
want to get back as buffer. Check the following example on how to get a user's profile photo:
export async function verifyLogin(email: string, password: string) {
const options = {
//...other config options
userPassword: password,
username: email,
attributes: ['thumbnailPhoto;binary', 'givenName', 'sn', 'sAMAccountName', 'userPrincipalName', 'memberOf' ]
};
try {
const ldapUser = await authenticate(options);
if (!ldapUser) {
return { error: "user not found" };
}
// accessing the image
const profilePhoto = ldapUser['thumbnailPhoto;binary'];
/* using the image
<img src={`data:image/*;base64,${user.profilePhoto}`} />
*/
return { user: ldapUser };
}
}
Version 2 supports Node version 12, 14, 15, 16, 17 and 18.
Version 3 supports Node version 15, 16, 17 and 18