NodeJS,passport,passport-ldap ConnectionError:ldaps://ldap.XXXX.com:636已关闭

时间:2015-03-18 12:00:46

标签: node.js active-directory passport.js

我试图在Windows上将一个工作的Nodejs服务器部署到Linux机器上。 使用passport-ldapauth模块登录我公司的LDAP服务器我得到了:

" ConnectionError:ldaps://ldap.XXX.com:636已关闭" 在Windows部署中,我没有遇到任何问题,

这是服务器代码:



var express = require('express')
	, http = require('http')
	, express = require('express')
	, routes = require('./routes')
	, http = require('http')
	, passport = require('passport')
	, flash = require('connect-flash')
	, fs = require('fs')
	, ldapStrategy = require('passport-ldapauth')
	, path = require('path');

var ldapGroupName = "XXX_GROUP";
var app = express();
var ldapOptions = {
	server : {
		url : 'ldaps://ldap.XXX.com:636',
		searchBase : 'o=XXX.com',
		searchFilter : '(uid={{username}})',
		tlsOptions : {
			ca : [ fs.readFileSync('/etc/ssl/certs/XXX.crt') ]
		}
	}
};

var opts = {
	filter : '(cn='+ldapGroupName+')',
	scope : 'sub'
};

//configure passport
passport.use(new ldapStrategy(ldapOptions));

var app = express();
var server = http.createServer(app);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.favicon());
app.use(express.logger()); 
app.use(express.bodyParser());

app.use(express.cookieParser());
app.use(express.json({limit: '50mb'}));
app.use(express.urlencoded({limit: '50mb'}));
app.use(express.session({secret:'Password'})); 
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'WebContent')));

  passport.serializeUser(function(user, done) {
	done(null, user);
});

passport.deserializeUser(function(id, done) {
	done(null, id);
});

   app.post('/login', function(req, res, next) {
	passport.authenticate('ldapauth', function(err, user, info) {
		if (info) {
			console.log('info: ' + info.message);
			res.send({
				status : 'err',
				message : info.message
			});
			return;
		}
		if (err) {
			console.log('err: ' + err);
			res.send({
				status : 'err',
				message : err
			});
			return;
		}
		if (!user) {
			return res.redirect('/');
		}
		req.logIn(user, function(err) {
			req.session.cookie.expires = new Date(Date.now() + 1000 * 60 * 30); 
			if (err) {
				return next(err);
			}
			return res.send({
				status : 'ok' , 
				name : user.givenName
			});
		});
	})(req, res, next);
});

server.listen(4002);
console.log("started port: 4002");




我错过了什么吗?我需要安装认证吗?

1 个答案:

答案 0 :(得分:0)

好的,我设法找到答案,在顶部添加到我的server.js:

process.env.NODE_TLS_REJECT_UNAUTHORIZED =" 0";

感谢:LDAP Bind Error using node.js and ldapjs