1 |
|
2 |
|
3 |
|
4 | import * as Logger from 'bunyan';
|
5 | import * as LdapAuth from '../lib/ldapauth';
|
6 |
|
7 | const log = new Logger({
|
8 | name: 'ldap',
|
9 | component: 'client',
|
10 | stream: process.stderr,
|
11 | level: 'trace'
|
12 | });
|
13 |
|
14 | const opts: LdapAuth.Options = {
|
15 | url: 'ldap://ldap.forumsys.com:389',
|
16 | bindDN: 'cn=read-only-admin,dc=example,dc=com',
|
17 | bindCredentials: 'password',
|
18 | searchBase: 'dc=example,dc=com',
|
19 | searchFilter: '(uid={{username}})',
|
20 | log: log,
|
21 | cache: true,
|
22 | includeRaw: true,
|
23 | groupSearchFilter: '(member={{dn}})',
|
24 | groupSearchBase: 'dc=example,dc=com'
|
25 | };
|
26 |
|
27 | const auth = new LdapAuth(opts);
|
28 |
|
29 | auth.on('error', (err) => {
|
30 | console.warn(err);
|
31 |
|
32 | });
|
33 |
|
34 | auth.authenticate('riemann', 'password', (err, user) => {
|
35 | if (err) {
|
36 | console.warn(err);
|
37 | auth.close(() => console.log('Unbound'));
|
38 | } else {
|
39 | console.log(user);
|
40 |
|
41 | auth.authenticate('riemann', 'password', (err, user) => {
|
42 | if (err) {
|
43 | console.warn(err);
|
44 | } else {
|
45 | console.log('Re-auth user DN:', user.dn);
|
46 | }
|
47 | auth.close();
|
48 | });
|
49 | }
|
50 | });
|