Skip to content

Instantly share code, notes, and snippets.

@gmoqa
Last active July 6, 2020 23:12
Show Gist options
  • Save gmoqa/a760938b942c71a433eaa1981e8a8321 to your computer and use it in GitHub Desktop.
Save gmoqa/a760938b942c71a433eaa1981e8a8321 to your computer and use it in GitHub Desktop.
Node.js LDAP Example
const express = require('express');
const passport = require('passport');
const ldap = require('passport-ldapauth');
const options = {
server: {
url: "ldap://ldap.forumsys.com",
bindDN: "cn=read-only-admin,dc=example,dc=com",
bindCredentials: 'password',
searchBase: "dc=example,dc=com",
searchFilter: "(uid={{username}})"
}
};
passport.use(new ldap(options));
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(passport.initialize());
app.post('/login', passport.authenticate('ldapauth', { session: false }), function(req, res) {
res.send({
status: 'ok',
user: req.user
});
});
app.listen(3000, () => {
console.log('Running...');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment