Skip to content

Instantly share code, notes, and snippets.

@fontanon
Created February 20, 2015 17:45
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save fontanon/99f69a45bf84bd0c3283 to your computer and use it in GitHub Desktop.
Save fontanon/99f69a45bf84bd0c3283 to your computer and use it in GitHub Desktop.
NodeJS Passport-LDAPAuth Express test
var express = require('express'),
passport = require('passport'),
bodyParser = require('body-parser'),
LdapStrategy = require('passport-ldapauth');
// Credentials from the free LDAP test server by forumsys
// More info at: http://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/
var OPTS = {
server: {
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}})'
}
};
var app = express();
passport.use(new LdapStrategy(OPTS));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(passport.initialize());
app.post('/login', function(req, res, next) {
passport.authenticate('ldapauth', {session: false}, function(err, user, info) {
if (err) {
return next(err); // will generate a 500 error
}
// Generate a JSON response reflecting authentication status
if (! user) {
return res.send({ success : false, message : 'authentication failed' });
}
return res.send({ success : true, message : 'authentication succeeded' });
})(req, res, next);
});
app.listen(3000);
@rushendragangalapudi
Copy link

how to send username and password for this code

@theccalderon
Copy link

how to send username and password for this code

See image from Postman attached.

Screen Shot 2019-03-14 at 2 00 12 PM

@csulit
Copy link

csulit commented Aug 30, 2019

Hmmm, can we use this to different DC?

@fontanon
Copy link
Author

Hmmm, can we use this to different DC?

I do not se why not! Just try :)

@rainkidpk
Copy link

<title>Error</title>
Error: connect ECONNREFUSED 52.87.186.93:389
            
   at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)

i get this error @@, can you help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment