gpt4 book ai didi

node.js - 在express中使用passport-ldapauth nodejs模块进行身份验证

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

我在 LDAP 服务器上验证用户身份时遇到问题。我将重要的代码粘贴在下面。谁能告诉我这个缺少哪些部分或者这个nodejs模块是否能够做我想做的事情?我已经尝试了两天了,但找不到解决方案。

const passport = require('passport');
const ldapStrategy = require('passport-ldapauth').Startegy;

var LDAP_OPTS = {
usernameField: 'myAccountUsername',
passwordField: 'myPassword',
server: {
url: 'ldap://xx.xx.x.xx:389',
bindDN: 'dn related data',
bindCredentials: 'adminAccountPassword',
searchBase: 'dc=xyz,dc=com',
searchFilter: '(sAmAccountName={{myUserNameForTheAccount}})'
},
};

passport.use(new ldapStrategy(LDAP_OPTS));

app.use(passport.initialize());


module.exports.login = function(req, res, next){


passport.authenticate('ldapauth', function(err, user, info){

console.log('inside authent '+JSON.stringify(info))

if(err){
return next(err);
}

if(!user){
res.status(401).json({ success: false, message: 'authentication failed' })
// res.send({success: false})
console.log('inside user: '+user)
} else {
res.status(200).json({success: true})
// res.send({success: true})
}

console.log('after response..')

})(req, res, next)

当我运行此程序时,我收到一条{“消息”:“缺少凭据”}。我用谷歌搜索了很多资源,但没有找到合适的资源。有使用“passport-local”的示例,但我找不到使用用户名和密码对用户进行身份验证的“passport-ldapauth”示例。即使在这个例子中,我们只是向 ldap 服务器发送了一个请求来检查用户是否存在,但我不知道如何在返回该用户的信息后验证他的密码。

最佳答案

passport-ldapauth的github页面链接到ldapauth-fork项目。根据文档,它说您需要将属性 bindProperty 添加到您的配置对象中。

ldapauth-fork 说 bindProperty 是

     /**
* Property of the LDAP user object to use when binding to verify
* the password. E.g. name, email. Default: dn
*/
bindProperty?: string;

希望能帮到你

关于node.js - 在express中使用passport-ldapauth nodejs模块进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50385444/

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