Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to fetch user & groups #214

Open
akkitech opened this issue Nov 28, 2019 · 2 comments
Open

Unable to fetch user & groups #214

akkitech opened this issue Nov 28, 2019 · 2 comments

Comments

@akkitech
Copy link

akkitech commented Nov 28, 2019

I am using node js activedirectory module for AD authentication and fetching users & groups. Able to authenticate successfully but unable to get users & groups using .findUser(), .findUsers(), .findGroups() methods. I've added few users and a group using ADSI editor in windows 10. Any clue what could be going wrong?

Screenshot of ADSI Editor :

image

Code :

var ActiveDirectory = require('activedirectory');
var config = {
    url: 'ldap://localhost',
    baseDN: 'cn=admin,dc=ec2,dc=internal',
    username: 'cn=akshay,cn=testContainer,cn=admin,dc=ec2,dc=internal',
    password: '123456'
};


var ad = new ActiveDirectory(config);

var username = 'cn=akshay,cn=testContainer,cn=admin,dc=ec2,dc=internal';
var password = '123456';

ad.authenticate(username, password, function (err, auth) {
    if (err) {
        console.log('ERROR: ' + JSON.stringify(err));
        return;
    }

    if (auth) {
        console.log('Authenticated!');
        ad.findUser({
            dn: "cn=akshay,cn=testContainer,cn=admin,dc=ec2,dc=internal"
        }, function (err, user) {
            if (err) {
                console.log('ERROR: ' + JSON.stringify(err));
                return;
            }

            if (!user) console.log('User: not found.');
            else console.log(JSON.stringify(user));
        });

    } else {
        console.log('Authentication failed!');
    }
});

Output :

Authenticated!
User: not found.

@KevinBeckers
Copy link

Did you solve this?

@akkitech
Copy link
Author

@KevinBeckers following syntax solved my problem:

ad.findUser("cn=akshay,cn=testContainer,cn=admin,dc=ec2,dc=internal", function(err, user) {
  if (err) {
    console.log('ERROR: ' +JSON.stringify(err));
    return;
  }
 
  if (! user) console.log('User not found');
  else console.log(JSON.stringify(user));
});

you could also pass [email protected] in the first parameter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants