I am currently working on my webapp. As of now, I can login with the username (sAMAccountName) but I want to login with the e-mail-adress. I looked up some backends, but none of them could help me.
Here are my setting.py
AUTH_LDAP_SERVER_URI = "ldap://192.168.4.123"
AUTH_LDAP_BIND_DN = "username"
AUTH_LDAP_BIND_PASSWORD = "password"
AUTH_LDAP_CONNECTION_OPTIONS = {
ldap.OPT_DEBUG_LEVEL: 1,
ldap.OPT_REFERRALS: 0
}
AUTH_LDAP_USER_SEARCH = LDAPSearch("DC=domain,DC=com", ldap.SCOPE_SUBTREE, "(sAMAccountName=%(user)s)")
AUTH_LDAP_GROUP_SEARCH = LDAPSearch("DC=domain,DC=com", ldap.SCOPE_SUBTREE, "(objectClass=group)")
AUTH_LDAP_GROUP_TYPE = NestedActiveDirectoryGroupType()
AUTH_LDAP_USER_ATTR_MAP = {
"first_name": "givenName",
"last_name": "sn",
"email": "mail",
"dn": "distinguishedName",
}
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
"is_active": "CN=users,cn=users,DC=domain,DC=com",
"is_staff": "CN=users,cn=users,DC=domain,DC=com",
"is_superuser": "CN=users,cn=users,DC=domain,DC=com"
}
AUTH_LDAP_ALWAYS_UPDATE_USER = True
LDAP_AUTH_OBJECT_CLASS = "inetOrgPerson"
AUTH_LDAP_FIND_GROUP_PERMS = True
AUTH_LDAP_CACHE_GROUPS = True
AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600
AUTHENTICATION_BACKENDS = (
'django_auth_ldap.backend.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
)
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler'
},
'stream_to_console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler'
},
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
'django_auth_ldap': {
'handlers': ['stream_to_console'],
'level': 'DEBUG',
'propagate': True,
},
}
}
Maybe you have a good backend or I am missing something. I also tried:
AUTH_LDAP_USER_SEARCH = LDAPSearch("DC=sbvg,DC=ch", ldap.SCOPE_SUBTREE, "(mail=%(user)s)")
but then it creates a user with the username user@domain.com, which is also wrong.