1 | Fork of [node-ldapauth](https://github.com/trentm/node-ldapauth) - A simple node.js lib to authenticate against an LDAP server.
|
2 |
|
3 | ## About the fork
|
4 |
|
5 | This fork was originally created and published because of an urgent need to get newer version of [ldapjs](http://ldapjs.org/) in use to [passport-ldapauth](https://github.com/vesse/passport-ldapauth) since the newer version supported passing `tlsOptions` to the TLS module. Since then a lot of issues from the original module ([#2](https://github.com/trentm/node-ldapauth/issues/2), [#3](https://github.com/trentm/node-ldapauth/issues/3), [#8](https://github.com/trentm/node-ldapauth/issues/8), [#10](https://github.com/trentm/node-ldapauth/issues/10), [#11](https://github.com/trentm/node-ldapauth/issues/11), [#12](https://github.com/trentm/node-ldapauth/issues/12), [#13](https://github.com/trentm/node-ldapauth/pull/13)) have been fixed, and new features have been added as well.
|
6 |
|
7 | Multiple [ldapjs](http://ldapjs.org/) client options have been made available.
|
8 |
|
9 | ## Usage
|
10 |
|
11 | ```javascript
|
12 | var LdapAuth = require('ldapauth-fork');
|
13 | var options = {
|
14 | url: 'ldaps://ldap.example.com:636',
|
15 | ...
|
16 | };
|
17 | var auth = new LdapAuth(options);
|
18 | ...
|
19 | auth.authenticate(username, password, function(err, user) { ... });
|
20 | ...
|
21 | auth.close(function(err) { ... })
|
22 | ```
|
23 |
|
24 | ## Install
|
25 |
|
26 | npm install ldapauth-fork
|
27 |
|
28 |
|
29 | ## License
|
30 |
|
31 | MIT. See "LICENSE" file.
|
32 |
|
33 |
|
34 | ## `LdapAuth` Config Options
|
35 |
|
36 | [Use the source Luke](https://github.com/vesse/node-ldapauth-fork/blob/master/lib/ldapauth.js#L35-L106)
|
37 |
|
38 |
|
39 | ## express/connect basicAuth example
|
40 |
|
41 | ```javascript
|
42 | var connect = require('connect');
|
43 | var LdapAuth = require('ldapauth-fork');
|
44 |
|
45 | // Config from a .json or .ini file or whatever.
|
46 | var config = {
|
47 | ldap: {
|
48 | url: "ldaps://ldap.example.com:636",
|
49 | bindDn: "uid=myadminusername,ou=users,o=example.com",
|
50 | bindCredentials: "mypassword",
|
51 | searchBase: "ou=users,o=example.com",
|
52 | searchFilter: "(uid={{username}})"
|
53 | }
|
54 | };
|
55 |
|
56 | var ldap = new LdapAuth({
|
57 | url: config.ldap.url,
|
58 | bindDn: config.ldap.bindDn,
|
59 | bindCredentials: config.ldap.bindCredentials,
|
60 | searchBase: config.ldap.searchBase,
|
61 | searchFilter: config.ldap.searchFilter,
|
62 | //log4js: require('log4js'),
|
63 | cache: true
|
64 | });
|
65 |
|
66 | var basicAuthMiddleware = connect.basicAuth(function (username, password, callback) {
|
67 | ldap.authenticate(username, password, function (err, user) {
|
68 | if (err) {
|
69 | console.log("LDAP auth error: %s", err);
|
70 | }
|
71 | callback(err, user)
|
72 | });
|
73 | });
|
74 | ```
|