Wednesday, 31 May 2017

Error Authenticating user with ldap from nodejs express and Passport-LDAP library

I am trying to authenticate user using my company's ldap server but whenever I try to login I get the below error, I am doing exactly as described in this example from this Github repo

Getting the ldap authentication request from user

app.post('/ldap', function (req, res, next) {
    passport.authenticate('ldap', function (err, user) {
        if(!user) {
            res.redirect("/login");
            console.log("error");
        }
        else {
            res.send(user);
        }
    })(req, res, next);
});

This is passport-ldap authentication code

var LdapStrategy = require('passport-ldapauth').Strategy;
passport.use('ldap', new LdapStrategy(
    {
        server: {
            url: 'Ldap URL',
            bindDn: 'cn=leafad,ou=service accounts,...',
            bindCredentials: 'PASSWORD',
            searchBase: ['OU=Internal','OU=Employees','OU=User Accounts'],
            searchFilter: '(sAMAccountName=)'
        },
        usernameField: 'username',
        passwordField: 'password',
        base: ['DC=ad']
    }, function (profile, done) {
        done(null, profile);
    }));

when I try to login I am getting following error:

SOME_PATH\route_manager\node_modules\ldapjs\lib\dn.js:171
     throw new TypeError('name (string) required');
     ^
TypeError: name (string) required

Can someone tell me if not this then what is the correct way to authenticate user.

I have gone through this already answered SO question but none of the answers helped me.



via warl0ck

No comments:

Post a Comment