Created
August 22, 2018 19:11
-
-
Save DecentM/7c2d2e26c8e887c544871889504f4562 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const LdapAuth = require('ldapauth-fork') | |
const pify = require('pify') | |
// https://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/ | |
const options = { | |
'url': 'ldap://ldap.forumsys.com:389', | |
'bindDN': 'cn=read-only-admin,dc=example,dc=com', | |
'bindCredentials': 'password', | |
'searchBase': 'dc=example,dc=com', | |
'searchFilter': 'uid={{username}}' | |
} | |
const client = new LdapAuth(options) | |
const username = 'galieleo' | |
const password = 'password' | |
const run = () => new Promise((resolve, reject) => { | |
client.authenticate(username, password, (error, user) => { | |
if (error) { | |
return reject(error) | |
} | |
return resolve(user) | |
}) | |
}) | |
const welcome = ({cn, mail,}) => { | |
console.log(`Welcome, ${cn}!`) | |
console.log(`Your e-mail address is "${mail}" according to the LDAP server.`) | |
} | |
console.log(` | |
================================= | |
Test LDAP authenticator with Node | |
================================= | |
Bind: ${options.bindDN} | |
Search base: ${options.searchBase} | |
Search filter: ${options.searchFilter} | |
Authenticating user "${username}" against "${options.url}"... | |
`) | |
run() | |
.then((r) => (welcome(r), process.exit(0))) | |
.catch((e) => (console.error('Caught', e), process.exit(1))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment