title: How to get a successful bind with company LDAP server
body: <p>I am setting up LDAP authentication for a website that my team created with MEAN stack (MongoDB, Express, Angular, and Node). However, my bind is unsuccessful.</p>
  
  <p>This work has been done on Windows 10. I am having trouble following the <a href="http://ldapjs.org/client.html" rel="nofollow noreferrer">ldap.js documentation</a> for client integration, but have found a <a href="https://github.com/joyent/node-ldapjs/issues/428#issuecomment-363922147" rel="nofollow noreferrer">Github issue</a> that seemed promising. I believe that my issue is with the bind API. My understanding is that I need to give it something in the server (I use my mailNickname, though I have also tried my userPrincipalName) and something private (my password). I used AD Explorer which allowed me to connect to the company server with my userPrincipalName (first.last@company.com) and password. I was able to search for myself within the server using several attributes like mailNickname and userPrincipalName, so I am unsure what is causing my binding error. </p>
  
  <p>We used the same server (with Active Directory) when establishing authentication for a Hygieia dashboard earlier this summer and AD Explorer worked well, so I am confident that I have the correct server.</p>
  
  <pre><code>var ldap = require('ldapjs');
  var assert = require('assert');
  
  // Create client and bind to AD
  var ldapClient = ldap.createClient({
      url: "ldap://servername.us.company.com:389"
  });
  
  
  ldapClient.bind(myDN, password, function(err) {
       assert.ifError(err);
  });
  
  
  var opts = {
      scope: 'sub',
      filter: '(mailNickname=NICKNAME4Testing)'
  };
  
  ldapClient.search('OU=AllUsers,DC=us,DC=company,DC=com', opts, function(err, res) {
      assert.ifError(err);
  
      res.on('searchEntry', function(entry) {
          console.log(entry.object.name);
          console.log(entry.object.dn);
      });
  
      res.on('searchReference', function(referral) {
          console.log('referral: ' + referral.uris.join());
      });
  
      res.on('error', function(err) {
          console.error('error: ' + err.message);
      });
  
      res.on('end', function(result) {
          console.log(result);
      });
  
  });
  </code></pre>
  
  <p>When I run npm start from the command line, I expect the output to be four lines on the terminal telling me my name, my DN, the search reference and 'end.' However, what I actually get is </p>
  
  <blockquote>
    <p>AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 80090308: >LdapErr: DSID-0C09042F, comment: AcceptSecurityContext error, data 52e, >v2580</p>
  </blockquote>
  
  <p>According to <a href="https://www.infrasightlabs.com/common-error-codes-for-active-directory-authentication" rel="nofollow noreferrer">another page that I found</a>, the problem may be with my password, but I am using exactly what I use to access my computer and the server through ADExplorer. There <em>is</em> a special character, but I have tried using both CHARACTER and \CHARACTER to no avail.</p>