jsumners / node-activedirectory

ActiveDirectory is an Node.js ldapjs client for authN (authentication) and authZ (authorization) for Microsoft Active Directory with range retrieval support for large Active Directory installations. Originally forked from gheeres/node-activedirectory.
MIT License
52 stars 43 forks source link

findUsers Result Limit 1000 #16

Closed jayrungta closed 7 years ago

jayrungta commented 7 years ago

So I am trying to query users using the findUsers function. However, the result I am getting is being limited to 1000 users only. I know for a fact that there are more than 1000 users that should be returned. Please tell me how do I go about getting the full results and not only 1000.

Here is an excerpt of the code I am using:

var opts = {
    filter: aSearchFilter,
    attributes: ["cn", "sAMAccountName", "employeeID", "description"]
}

let exportedMethods = {
    getAllUsers() {
        return new Promise((resolve, reject) => {
            ad.findUsers(opts, function(err, users) {
                if (err) {
                    console.log('ERROR: ' +JSON.stringify(err));
                    return;
                }
                if ((! users) || (users.length == 0)) {
                    console.log('No users found.');
                    reject('No users found.')
                    return;
                }
                else {
                    console.log('findUsers: '+JSON.stringify(users));
                    resolve(users);
                }
            });
        });
    }
}
module.exports = exportedMethods;
jsumners commented 7 years ago

That's Active Directory's natural result limitation. You need to pass in an options object with the ldapjs paged option enabled.

jayrungta commented 7 years ago

Thank you for the quick response.

If I were to turn on paging, how would I go about parsing each page of results? Would the response have event handling like explained on the ldapjs website?

 res.on('page', function(result) {
    console.log('page end');
  });
jsumners commented 7 years ago

I'm not intimately familiar with this codebase any longer, and the docs have always been lacking. If I recall correctly, once paging is enabled this library will pull back everything and return the results to you in one big array/object.

jayrungta commented 7 years ago

You are absolutely right. The moment I set paged = true, I started getting all the results. It definitely needs better documentation.

Thanks again for helping me so quickly. Cheers!

jsumners commented 7 years ago

@jayrungta glad you got it working. I am definitely open to PRs for documentation.