title: Binding to Active Directory using django-auth-ldap
body: <p>I'm trying to create user login authentication in my django app via Active Directory using <strong>django-auth-ldap</strong>. The problem is that I cannot bind to the AD using <strong>username</strong> (which is <em>sAMAccountName</em> LDAP equivalent). Part of my settings.py below:</p>
  
  <pre><code>import ldap
  from django_auth_ldap.config import LDAPSearch
  
  AUTHENTICATION_BACKENDS = [
      'django_auth_ldap.backend.LDAPBackend',
  ]
  
  AUTH_LDAP_START_TLS = False
  AUTH_LDAP_ALWAYS_UPDATE_USER = False
  AUTH_LDAP_SERVER_URI = 'ldap://ip_address:389'
  AUTH_LDAP_BIND_DN = ''
  AUTH_LDAP_BIND_PASSWORD = ''
  AUTH_LDAP_USER_SEARCH = LDAPSearch('DC=example,DC=com', ldap.SCOPE_SUBTREE, '(sAMAccountName=%(user)s)')
  AUTH_LDAP_CONNECTION_OPTIONS = {
      ldap.OPT_REFERRALS: 0,
  }
  </code></pre>
  
  <p><strong>Console log:</strong></p>
  
  <pre><code>ERROR search_s('DC=example,DC=com', 2, '(sAMAccountName=user)') raised OPERATIONS_ERROR({'desc': 'Operations error', 'info': '00000000: LdapErr: DSID-0C090627, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, vece'})
  DEBUG search_s('DC=example,DC=com', 2, '(sAMAccountName=%(user)s)') returned 0 objects:
  DEBUG Authentication failed for user: failed to map the username to a DN.
  </code></pre>
  
  <p>Any idea why this is not working?</p>