etianen / django-python3-ldap

Django LDAP user authentication backend for Python 3.
BSD 3-Clause "New" or "Revised" License
412 stars 119 forks source link

LDAP bind failed: LDAPInvalidCredentialsResult - 49 - invalidCredentials - None - 80090308: LdapErr: DSID-0C090439, comment: AcceptSecurityContext error, data 52e, v4563 - bindResponse - None #243

Closed MikeEunLim closed 2 years ago

MikeEunLim commented 2 years ago

ldap sync works fine (venv) C:\perforce_workspace\Python\djangoProject>python manage.py ldap_sync_users LDAP connect succeeded LDAP user lookup succeeded Synced django_agent LDAP user lookup succeeded Synced e###### LDAP user lookup succeeded Synced e######

Here is my Settings.py

LDAP_AUTH_USE_TLS = True

LDAP Connection Settings

LDAP_AUTH_HOST = 'XXXXXXXXXXX' LDAP_AUTH_PORT = 636 LDAP_AUTH_URL = 'ldaps://{host}:{port}'.format( host=LDAP_AUTH_HOST, port=LDAP_AUTH_PORT, ) LDAP_AUTH_SEARCH_BASE = "DC=XXXXXX,DC=XXXXX" LDAP_AUTH_OBJECT_CLASS = "organizationalPerson" LDAP_AUTH_USER_LOOKUP_FIELDS = ("username",)

LDAP_AUTH_CLEAN_USER_DATA = "django_python3_ldap.utils.clean_user_data"

AUTHENTICATION_BACKENDS = ( "django_python3_ldap.auth.LDAPBackend", "django.contrib.auth.backends.ModelBackend", )

LDAP_AUTH_USER_FIELDS = { "username": "sAMAccountName", "first_name": "givenName", "last_name": "sn", "email": "mail", } AUTH_LDAP_USER_ATTR_MAP = { "first_name": "givenName", "last_name": "sn", "email":"mail", }

Custom setting

LDAP_AUTH_SYNC_USER_RELATIONS = "djangoProject.ldap.sync_all_user_group_relations"

LDAP_AUTH_SYNC_USER_RELATIONS = "django_python3_ldap.utils.sync_user_relations"

Custom setting

LDAP_AUTH_FORMAT_SEARCH_FILTERS = "djangoProject.ldap.custom_format_search_filters"

LDAP_AUTH_FORMAT_SEARCH_FILTERS = "django_python3_ldap.utils.format_search_filters"

LDAP_AUTH_FORMAT_USERNAME = "django_python3_ldap.utils.format_username_active_directory"

LDAP_AUTH_CONNECTION_USERNAME = "xxxxxxxxxxxxx" LDAP_AUTH_CONNECTION_PASSWORD = "xxxxxxxxxxx"

LDAP_AUTH_ACTIVE_DIRECTORY_DOMAIN = "xxxxxx"

Set connection/receive timeouts (in seconds) on the underlying ldap3 library.

LDAP_AUTH_CONNECT_TIMEOUT = None LDAP_AUTH_RECEIVE_TIMEOUT = None

here is my format search base on Group members of

from django_python3_ldap.utils import format_search_filters

def custom_format_search_filters(ldap_fields):

Call the base format callable.

search_filters = format_search_filters(ldap_fields)
# Advanced: apply custom LDAP filter logic.
search_filters.append("(&(memberOf=CN=django_staff,OU=django,DC=xxx,DC=xxx))")
# All done!
return search_filters

Look like I fix my own issue lol LDAP_AUTH_ACTIVE_DIRECTORY_DOMAIN = "domain" I used lowercase used to be all cap.....

MikeEunLim commented 2 years ago

weirdly while writing this I just resolved it.