UNPKG

947 BJavaScriptView Raw
1var express = require('express'),
2 passport = require('passport'),
3 LdapStrategy = require('passport-ldapauth').Strategy;
4
5var server = null;
6
7var init_passport = function(opts, testopts) {
8 if (testopts.no_callback === true) {
9 passport.use(new LdapStrategy(opts));
10 } else {
11 passport.use(new LdapStrategy(opts, function(user, cb) {
12 return cb(null, user);
13 }));
14 }
15};
16
17exports.start = function(opts, testopts, cb) {
18
19 var app = express();
20
21 init_passport(opts, testopts);
22
23 app.configure(function() {
24 app.use(express.bodyParser());
25 app.use(passport.initialize());
26 });
27
28 app.post('/login', passport.authenticate('ldapauth', {session: false}), function(req, res) {
29 res.send({status: 'ok'});
30 });
31
32 if (typeof cb === 'function') return cb(app);
33 return;
34};
35
36exports.close = function(cb) {
37 if (server) server.close();
38 server = null;
39 if (typeof cb === 'function') return cb();
40 return;
41};