Skip to content

Instantly share code, notes, and snippets.

@DecentM
Created August 22, 2018 19:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DecentM/7c2d2e26c8e887c544871889504f4562 to your computer and use it in GitHub Desktop.
Save DecentM/7c2d2e26c8e887c544871889504f4562 to your computer and use it in GitHub Desktop.
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