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