gheeres / 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.
MIT License
534 stars 146 forks source link

Problem getting membership for user #130

Closed javitrekkor closed 8 years ago

javitrekkor commented 8 years ago

Hi! first of all, great job! I have the next code, and I was searching on the issues panel for this problem, and my code is the next:

var ActiveDirectory = require('activedirectory');

var url = 'ldap://11.0.0.15';
var baseDN = 'dc=domain,dc=com';
var username = 'administrator@adtest.com';
var password = 'pass';

var config = {url:url,
                baseDN: baseDN,
                    logging:{
                    name:'ActiveDirectory',
                    streams: [
                        {level: 'debug',
                        stream: process.stdout}
                    ]
                }};

var ad = new ActiveDirectory(config);

ad.authenticate(username, password, function(err, auth) {
    if (err) {

        console.log('ERROR: '+JSON.stringify(err));
        return;
    }

    if (!auth) {

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

        console.log('Authenticated!');

        var opts = {
            bindDN: username,
            bindCredentials: password
        };

        var adUser = 'user1@adtest.com';

        ad.getGroupMembershipForUser(opts, adUser, function (err, groups) {
            if (err) {
                console.log('ERROR: ' + JSON.stringify(err));
                return;
            }
            if (!groups) console.log('User: ' + username + ' not found.');
            else console.log(JSON.stringify(groups));
        });
    }
});

The problem is the next on the log:

{"name":"ActiveDirectory","hostname":"jas-dev_nodejs","pid":2516,"level":50,"err":{"message":"0000202B: RefErr: DSID-031007EF, data 0, 1 access points\n\tref 1: 'domain.com'\n\u0000","name":"ReferralError","stack":"ReferralError: 0000202B: RefErr: DSID-031007EF, data 0, 1 access points\n\tref 1: 'domain.com'\n\u0000\n at messageCallback (c:\Users\Administrator\WebstormProjects_test\ActiveDirectory\node_modules\ldapjs\lib\client\client.js:1419:45)\n at Parser.onMessage (c:\Users\Administrator\WebstormProjects_test\ActiveDirectory\node_modules\ldapjs\lib\client\client.js:1089:14)\n at Parser.emit (events.js:107:17)\n at Parser.write (c:\Users\Administrator\WebstormProjects_test\ActiveDirectory\node_modules\ldapjs\lib\messages\parser.js:117:8)\n at Socket.onData (c:\Users\Administrator\WebstormProjects_test\ActiveDirectory\node_modules\ldapjs\lib\client\client.js:1076:22)\n at Socket.emit (events.js:107:17)\n at readableAddChunk (_stream_readable.js:163:16)\n at Socket.Readable.push (_stream_readable.js:126:10)\n at TCP.onread (net.js:538:20)","code":10},"msg":"[UNKNOWN] An error occurred performing the requested LDAP search on dc=domain,dc=com ({\"bindDN\":\"administrator@adtest.com\",\"bindCredentials\":\"@dmin2016\",\"filter\":\"(&(objectCategory=User)(|(sAMAccountName=user1@adtest.com)(userPrincipalName=user1@adtest.com)))\",\"scope\":\"sub\",\"attributes\":[],\"controls\":[{\"_value\":{\"size\":1000},\"type\":\"1.2.840.113556.1.4.319\",\"criticality\":false,\"value\":{\"size\":1000},\"json\":{\"controlType\":\"1.2.840.113556.1.4.319\",\"criticality\":false,\"controlValue\":{\"size\":1000}}}]})","time":"2016-04-14T11:15:34.065Z","v":0} ERROR: {"dn":"","code":10,"name":"ReferralError","message":"0000202B: RefErr: DSID-031007EF, data 0, 1 access points\n\tref 1: 'domain.com'\n\u0000"}

I dont know why Im getting this error.

gheeres commented 8 years ago

Make sure that your baseDn is set correctly for the domain controller you can calling. If you don't know what it is, then you can use the getRootDSE method.

The error you are receiving indicates a referral error. Do you have referrals in your AD configuration? If not, then you have configuration problems.

javitrekkor commented 8 years ago

Yes, you were rigth. I was naming wrong DC fields. Thank you!