node-ldapauth icon indicating copy to clipboard operation
node-ldapauth copied to clipboard

Binding problem

Open mkermani144 opened this issue 9 years ago • 1 comments

When I try to use node-ldapauth, I get the following error:

Error: LDAP connection is not yet bound
...

My code seems like this:

var config = {
        ldap: {
            url: "ldap://1.2.3.4",
            adminDn: "cn=admin, dc=sub, dc=domain",
            adminPassword: "Secret",
            searchBase: "dc=sub, dc=domain",
            searchFilter: "(cn={{username}})" 
        }
    };
var auth = new ldap({
    url: config.ldap.url,
    adminDn: config.ldap.adminDn,
    adminPassword: config.ldap.adminPassword,
    searchBase: config.ldap.searchBase,
    searchFilter: config.ldap.searchFilter
});
auth.authenticate('cn=sample , ou=sub1, ou=sub2, dc=sub, dc=domain', 'samplesecret', function(err, user) {
        if (err) {
            console.log(err);
            res.writeHead('401');
            res.end()
        } else {
            res.writeHead('200');
            res.end();
        }
    });

I am sure that the credentials are valid. I also tried cn=sample instead of cn={{username}} but the problem does not resolve. Any idea?

mkermani144 avatar Aug 28 '16 08:08 mkermani144

From the source code:

*
 *    // If you want to be lazier you can skip waiting for 'connect'. :)
 *    // It just means that a quick `.authenticate()` call will likely fail
 *    // while the LDAP connect and bind is still being done.
 *    auth.once('connect', function () {
 *        ...
 *        auth.authenticate(username, password, function (err, user) { ... });
 *        ...
 *        auth.close(function (err) { ... })
 *    });
 */

luiselizondo avatar Nov 17 '16 01:11 luiselizondo