I’m trying to make a connection to AD via LDAP with django-auth-ldap and I’m not succeeding.
I’ve tried everything, I think.
this is my code:
# The URL of the LDAP server.
AUTH_LDAP_SERVER_URI = "ldap://my_ldap"
AUTH_LDAP_START_TLS=True
AUTH_LDAP_GLOBAL_OPTION={
ldap.OPT_PROTOCOL_VERSION: 3,
ldap.OPT_X_TLS_REQUIRE_CERT:ldap.OPT_X_TLS_NEVER,
ldap.OPT_X_TLS_NEWCTX:0,
ldap.OPT_REFERRALS:0
}
# Set up the basic group parameters.
AUTH_LDAP_USER_DN_TEMPLATE = 'cn=%(user)s,OU=myCompany,DC=myCompany,DC=pt'
#I try boot TEMPLATE and USER_SEARCH
#AUTH_LDAP_USER_SEARCH = LDAPSearch(
# OU=USERS,OU=DA,OU=myCompany,DC=myCompany,DC=pt",
# ldap.SCOPE_SUBTREE,
# samaccountname=%(user)s")
# Populate the Django user from the LDAP directory.
AUTH_LDAP_USER_ATTR_MAP = {
"first_name": "givenName",
"last_name": "sn",
"email": "mail",
}
AUTH_LDAP_CACHE_TIMEOUT = 3600
AUTHENTICATION_BACKENDS = (
"django_auth_ldap.backend.LDAPBackend",
"django.contrib.auth.backends.ModelBackend",
)
Caught LDAPError while authenticating cpc417: CONNECT_ERROR({‘desc’: ‘Connect error’, ‘info’: ‘error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed (unable to get local issuer certificate)’})
But, I can connect with django-python3-ldap.
This is the code:
# The URL of the LDAP server.
LDAP_AUTH_URL = "ldap://my_ldap"
LDAP_AUTH_USE_TLS = True
import ssl
LDAP_AUTH_TLS_VERSION = ssl.PROTOCOL_TLSv1_2
LDAP_AUTH_SEARCH_BASE ="OU=DA,OU=myCompany,DC=myCompany,DC=pt"
# The LDAP class that represents a user.
LDAP_AUTH_OBJECT_CLASS = "user"
# A tuple of django model fields used to uniquely identify a user.
LDAP_AUTH_USER_LOOKUP_FIELDS = ("username",)
LDAP_AUTH_CONNECTION_USERNAME = None
LDAP_AUTH_CONNECTION_PASSWORD = None
# Set connection/receive timeouts (in seconds) on the underlying `ldap3` library.
LDAP_AUTH_CONNECT_TIMEOUT = None
LDAP_AUTH_RECEIVE_TIMEOUT = None
LDAP_AUTH_FORMAT_USERNAME = "django_python3_ldap.utils.format_username_active_directory_principal"
LDAP_AUTH_ACTIVE_DIRECTORY_DOMAIN = "myCompany.pt"
AUTHENTICATION_BACKENDS = (
'django_python3_ldap.auth.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
)
LDAP_AUTH_SYNC_USER_RELATIONS ="django_python3_ldap.utils.sync_user_relations"
LDAP_AUTH_USER_FIELDS = {
"username": "sAMAccountName",
"first_name": "givenName",
"last_name": "sn",
"email": "mail",
}
Can someone help me with setting up the link with django-auth-ldap?