简体   繁体   English

在Express中使用通行证-ldapauth nodejs模块进行身份验证

[英]Authentication with passport-ldapauth nodejs module in express

I'm having issues authentication authenticate an user for an ldap server. 我在验证ldap服务器的用户身份时遇到问题。 I'm pasting the important code below. 我要粘贴下面的重要代码。 Can anyone tell me what are the missing pieces of this or whether this nodejs module is able to do what I want to do? 谁能告诉我这是缺少的部分,或者这个nodejs模块是否能够执行我想做的事情? I've been trying this for two days now and couldn't find a solution. 我已经尝试了两天了,却找不到解决方案。

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)

When I run this I get a {"message":"Missing credentials"}. 运行此命令时,我得到一个{“ message”:“ Missing certificate”}。 I googled for many resources but haven't found a proper one. 我在Google上搜索了许多资源,但没有找到合适的资源。 There are examples using "passport-local" but I couldn't find "passport-ldapauth" example that has authenticating an user with his username & password. 有使用“ passport-local”的示例,但找不到使用用户名和密码对用户进行身份验证的“ passport-ldapauth”示例。 Even in this exapmle, we just sent a request to ldap server to check the existence of an user but I don't know how to validate his password after returning the information of that user. 即使在此示例中,我们也只是向ldap服务器发送了一个请求,以检查用户的存在,但是我不知道如何在返回该用户的信息后验证其密码。

The github page of passport-ldapauth links to ldapauth-fork project. 护照-ldapauth的github页面链接到ldapauth-fork项目。 According to the documentation it says that you need to add the property bindProperty to your configuration object. 根据文档,它说您需要将属性bindProperty添加到配置对象中。

ldapauth-fork says that bindProperty is 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;

Hope that can help 希望能有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM