8

I am trying to install django-auth-ldap in my windows system it shows the following error

\pip-build-3x6rkxb4\pyldap\modules\errors.h(8): fatal error C1083: Cannot open include file: 'lber.h': No such file or directory error: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe' failed with exit status 2

# LDAP auth settings.
LDAP_AUTH_URL = os.environ.get("LDAP_AUTH_URL", "ldap://xxx.xx.xx.xx:389")
LDAP_AUTH_USE_TLS = False

LDAP_AUTH_SEARCH_BASE = "dc=maxcrc,dc=com" 
LDAP_AUTH_OBJECT_CLASS = "inetOrgPerson"
LDAP_AUTH_USER_FIELDS = {
    "username": "uid",
    "first_name": "givenName",
    "last_name": "sn",
    "email": "mail",
}
LDAP_AUTH_USER_LOOKUP_FIELDS = ("username",)
LDAP_AUTH_CLEAN_USER_DATA = "django_python3_ldap.utils.clean_user_data"
LDAP_AUTH_SYNC_USER_RELATIONS = "django_python3_ldap.utils.sync_user_relations"
LDAP_AUTH_FORMAT_SEARCH_FILTERS = "django_python3_ldap.utils.format_search_filters"
LDAP_AUTH_FORMAT_USERNAME = "django_python3_ldap.utils.format_username_openldap"
LDAP_AUTH_ACTIVE_DIRECTORY_DOMAIN = None 
LDAP_AUTH_CONNECTION_USERNAME = "cn=Manager,dc=maxcrc,dc=com" 
LDAP_AUTH_CONNECTION_PASSWORD = "*****" 

LDAP_AUTH_CONNECT_TIMEOUT = None
LDAP_AUTH_RECEIVE_TIMEOUT = None

AUTHENTICATION_BACKENDS = (
    "django_python3_ldap.auth.LDAPBackend",
)

My versions are Python - 3.6.3 (64bit) Django - 1.11.6 (64bit) Windows 10 - 64bit

Thanks

2 Answers 2

10

django-auth-ldap needs to be compiled due to its dependencies. Especially on Windows, I'd recommend trying a pure Python solution. The one I use which works very well, is django-python3-ldap, which you can find here:

https://github.com/etianen/django-python3-ldap

Here is how I set up the settings, so that we can connect using these values with ldap3 directly as well:

AUTHENTICATION_BACKENDS = [
    'django.contrib.auth.backends.ModelBackend',
    'django_python3_ldap.auth.LDAPBackend',
]

# LDAP Connection Settings
LDAP_AUTH_HOST = 'ldap.example.com'
LDAP_AUTH_PORT = 636
LDAP_AUTH_URL = 'ldaps://{host}:{port}'.format(
    host=LDAP_AUTH_HOST,
    port=LDAP_AUTH_PORT,
)
LDAP_AUTH_CONNECTION_USERNAME = 'ldapuser'
LDAP_AUTH_CONNECTION_PASSWORD = 'ldappassword'

# Initiate TLS on connection.
LDAP_AUTH_USE_TLS = True

# The LDAP search base for looking up users.
LDAP_AUTH_SEARCH_BASE = "ou=People,dc=example,dc=com"

# The LDAP class that represents a user.
LDAP_AUTH_OBJECT_CLASS = "shadowAccount"

# User model fields mapped to the LDAP
# attributes that represent them.
LDAP_AUTH_USER_FIELDS = {
    "username": "uid",
}

# A tuple of fields used to uniquely identify a user.
LDAP_AUTH_USER_LOOKUP_FIELDS = ("username",)

The README also includes instructions for Active Directory, if that's what you're connecting to. Good luck!

7
  • Thanks for your reply. Right now I am working in "django-python3-ldap". I have configured the setting.py as follow as their document and I can run the "python manage.py ldap_sync_users" command to synchronized the data to my database. But If I am trying to authenticate via my view.py it returned the "LDAP connect failed: LDAPInvalidCredentialsResult - 49 - invalidCredentials - None - None - bindResponse - None" error.
    – Murali
    Commented Nov 1, 2017 at 12:23
  • Are you trying to connect to Active Directory or OpenLDAP? Do you know what LDAP schema you're using? It sounds like it is connecting, but your configuration settings need to be tweaked to authenticate properly.
    – FlipperPA
    Commented Nov 1, 2017 at 17:21
  • I am using OpenLDAP but not sure about the schema been used. I have updated configuration settings detail in my question section.
    – Murali
    Commented Nov 2, 2017 at 6:37
  • We used shadowAccount. I've amended my answer to include an example configuration for this setup. You can connect to your OpenLDAP server and browse your schema with something like LDAPAdmin: ldapadmin.org
    – FlipperPA
    Commented Nov 2, 2017 at 11:21
  • I have fixed this issue. Thanks FlipperPA
    – Murali
    Commented Nov 7, 2017 at 3:39
5

For those who, like me, cannot leave django-auth-ldap for whatever reason: I solved downloading and installing the binary wheel of python-ldap from here

https://www.lfd.uci.edu/~gohlke/pythonlibs/#python-ldap

I hope this helps

2
  • The link is no longer accessible
    – Frank Fang
    Commented Jun 30 at 3:39
  • Sad news: looks like C Gohlke stopped supporting the unofficial binaries. The link from his home page: cgohlke.com to the binaries is also broken. Commented Oct 29 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.