Last active
July 6, 2020 23:12
-
-
Save gmoqa/a760938b942c71a433eaa1981e8a8321 to your computer and use it in GitHub Desktop.
Node.js LDAP Example
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 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