如何使用passport-ldapauth npm

时间:2015-10-06 06:40:06

标签: node.js ldap passport.js

在下面的代码中,有人可以帮助我解决我的错误吗?没有打印控制台消息。我正在寻找在节点v4.1.1中支持的ldap客户端npm

var passport = require('passport'),
    LdapStrategy = require('passport-ldapauth');

// Credentials from the free LDAP test server by forumsys
// More info at: http://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/
var OPTS = {
    server: {
        url: 'ldap://IP:PORT',
        bindDn: <admin username>,
        bindCredentials: <admin password>,
        usernameField: <username>,
        passwordField: <pass>
    }
};

passport.use(new LdapStrategy(OPTS));

passport.authenticate('ldapauth', {session: false}, function (err, user, info) {
    console.log(info);
    if (err) {
        console.log(err); // will generate a 500 error
    }
    // Generate a JSON response reflecting authentication status
    if (!user) {
        console.log("authentication failed");
    }
    console.log("authentication succeeded");
})

0 个答案:

没有答案