ldap-authentication
Advanced tools
Comparing version 2.1.1 to 2.1.2
19
index.js
@@ -42,3 +42,3 @@ const assert = require('assert') | ||
var filter = new ldap.filters.EqualityFilter({ | ||
attribute: usernameAttribute, | ||
attribute: usernameAttribute, | ||
value: username | ||
@@ -85,3 +85,3 @@ }) | ||
ldapOpts.log && ldapOpts.log.trace(`admin did not find user! (${usernameAttribute}=${username})`) | ||
throw new Error('user not found or usernameAttribute is wrong') | ||
throw new LdapAuthenticationError('user not found or usernameAttribute is wrong') | ||
} | ||
@@ -104,3 +104,3 @@ var userDn = user.dn | ||
ldapOpts.log && ldapOpts.log.trace(`user logged in, but user details could not be found. (${usernameAttribute}=${username}). Probabaly wrong attribute or searchBase?`) | ||
throw new Error('user logged in, but user details could not be found. Probabaly usernameAttribute or userSearchBase is wrong?') | ||
throw new LdapAuthenticationError('user logged in, but user details could not be found. Probabaly usernameAttribute or userSearchBase is wrong?') | ||
} | ||
@@ -148,3 +148,16 @@ ldapUserClient.unbind() | ||
class LdapAuthenticationError extends Error { | ||
constructor(message) { | ||
super(message) | ||
// Ensure the name of this error is the same as the class name | ||
this.name = this.constructor.name | ||
// This clips the constructor invocation from the stack trace. | ||
// It's not absolutely essential, but it does make the stack trace a little nicer. | ||
// @see Node.js reference (bottom) | ||
Error.captureStackTrace(this, this.constructor); | ||
} | ||
} | ||
module.exports.authenticate = authenticate | ||
module.exports.LdapAuthenticationError = LdapAuthenticationError | ||
{ | ||
"name": "ldap-authentication", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "A simple async nodejs library for LDAP user authentication", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# A Simple node Library that Authenticates a User Against an LDAP/AD Server | ||
[![Build Status](https://travis-ci.org/shaozi/ldap-authentication.svg?branch=master)](https://travis-ci.org/shaozi/ldap-authentication) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/shaozi/ldap-authentication/badge.svg?targetFile=package.json)](https://snyk.io/test/github/shaozi/ldap-authentication?targetFile=package.json) | ||
This library use `ldapjs` as the underneath library. It has two modes of authentications: | ||
@@ -34,2 +37,6 @@ | ||
* An example on how to use with Passport is [passport-ldap-example](https://github.com/shaozi/passport-ldap-example) | ||
* Another simple library [express-passport-ldap-mongoose](https://github.com/shaozi/express-passport-ldap-mongoose) provide turn key solution | ||
#### User authenticate without getting user details | ||
@@ -36,0 +43,0 @@ |
@@ -1,2 +0,2 @@ | ||
const { authenticate } = require('../index.js') | ||
const { authenticate, LdapAuthenticationError } = require('../index.js') | ||
@@ -182,2 +182,21 @@ describe('ldap-authentication test', () => { | ||
}) | ||
test('Wrong options give LdapAuthenticationError', async () => { | ||
let options = { | ||
ldapOpts: { | ||
url: 'ldap://ldap.forumsys.com' | ||
}, | ||
userDn: 'uid=einstein,dc=example,dc=com', | ||
userPassword: 'password', | ||
usernameAttribute: 'cn', | ||
userSearchBase: 'dc=example,dc=com', | ||
username: 'einstein' | ||
} | ||
try { | ||
await authenticate(options) | ||
} catch(error) { | ||
e = error | ||
} | ||
expect(e).toBeTruthy() | ||
expect(e).toBeInstanceOf(LdapAuthenticationError) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17579
6
381
134