gpt4 book ai didi

node.js - NodeJS、 Passport 、 Passport -ldap ConnectionError : ldaps://ldap. XXXX.com:636 已关闭

转载 作者:太空宇宙 更新时间:2023-11-04 02:28:05 26 4
gpt4 key购买 nike

我正在尝试在 Windows 到 Linux 计算机上部署一个工作 Nodejs 服务器。使用 Passport-ldapauth 模块登录我们公司的 LDAP 服务器,我得到:

“连接错误: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");

我是不是漏掉了什么?我需要安装认证吗?

最佳答案

好吧,我设法找到了答案,将其添加到顶部的 server.js 中:

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

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

关于node.js - NodeJS、 Passport 、 Passport -ldap ConnectionError : ldaps://ldap. XXXX.com:636 已关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29121502/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com