aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJohannes Zellner <johannes@nebulon.de>2015-06-27 19:59:20 +0200
committerJohannes Zellner <johannes@nebulon.de>2015-06-27 19:59:20 +0200
commita90a633f030f44bd8142e1d44a8312e952e620bb (patch)
tree9aa8c7842d4942b4d5728159a723b6dc1d16ca76 /src
parentb72caa6940baba0eb75a7ad9618c57cc771d44cf (diff)
downloadSurfer-a90a633f030f44bd8142e1d44a8312e952e620bb.tar.gz
Surfer-a90a633f030f44bd8142e1d44a8312e952e620bb.tar.zst
Surfer-a90a633f030f44bd8142e1d44a8312e952e620bb.zip
Add auth to client
Diffstat (limited to 'src')
-rw-r--r--src/auth.js24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/auth.js b/src/auth.js
index 3d2acce..83d0426 100644
--- a/src/auth.js
+++ b/src/auth.js
@@ -3,20 +3,30 @@
3var passport = require('passport'), 3var passport = require('passport'),
4 LdapStrategy = require('passport-ldapjs').Strategy; 4 LdapStrategy = require('passport-ldapjs').Strategy;
5 5
6passport.serializeUser(function (user, done) {
7 console.log('serializeUser', user);
8 done(null, user.id);
9});
10
11passport.deserializeUser(function (id, done) {
12 console.log('deserializeUser', id);
13 done(null, { id: id });
14});
15
6var LDAP_URL = process.env.LDAP_URL; 16var LDAP_URL = process.env.LDAP_URL;
7var LDAP_USERS_BASE_DN = process.env.LDAP_USERS_BASE_DN; 17var LDAP_USERS_BASE_DN = process.env.LDAP_USERS_BASE_DN;
8 18
9if (LDAP_URL && LDAP_USERS_BASE_DN) { 19if (LDAP_URL && LDAP_USERS_BASE_DN) {
10 console.log('Enable ldap auth'); 20 console.log('Enable ldap auth');
11 21
12 exports.ldap = passport.authenticate('ldap', { 22 exports.ldap = passport.authenticate('ldap');
13 successReturnToOrRedirect: '/',
14 failureRedirect: '/login',
15 failureFlash: true
16 });
17} else { 23} else {
18 exports.ldap = function (req, res, next) { 24 exports.ldap = function (req, res, next) {
19 console.log('ldap auth disabled'); 25 console.log('Disable ldap auth, use developer credentials!');
26
27 if (req.query.username !== 'username') return res.send(401);
28 if (req.query.password !== 'password') return res.send(401);
29
20 next(); 30 next();
21 }; 31 };
22} 32}
@@ -31,7 +41,7 @@ var opts = {
31 attributes: ['displayname', 'username', 'mail', 'uid'], 41 attributes: ['displayname', 'username', 'mail', 'uid'],
32 scope: 'sub' 42 scope: 'sub'
33 }, 43 },
34 uidTag: 'uid', 44 uidTag: 'cn',
35 usernameField: 'username', 45 usernameField: 'username',
36 passwordField: 'password', 46 passwordField: 'password',
37}; 47};