Skip to content

Instantly share code, notes, and snippets.

@lancechentw
Created February 19, 2014 10:58
Show Gist options
  • Save lancechentw/9089843 to your computer and use it in GitHub Desktop.
Save lancechentw/9089843 to your computer and use it in GitHub Desktop.
import ldap
# ldap server settings
AUTH_LDAP_SERVER_URI = "ldap://ldap.example.com"
AUTH_LDAP_START_TLS = True
# User DN for authentication
AUTH_LDAP_USER_DN_TEMPLATE = 'uid=%(user)s,ou=People,dc=example,dc=com'
# Restrict log in to only members that belong to staff group
from django_auth_ldap.config import LDAPSearch, PosixGroupType
AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
"ou=Group,dc=example,dc=com",
ldap.SCOPE_SUBTREE,
"(objectClass=posixGroup)"
)
AUTH_LDAP_GROUP_TYPE = PosixGroupType()
AUTH_LDAP_REQUIRE_GROUP = "cn=staff,ou=Group,dc=example,dc=com"
# Override AUTHENTICATION_BACKENDS
AUTHENTICATION_BACKENDS = (
'django_auth_ldap.backend.LDAPBackend',
)
# Preserve original database auth backend and social auth backends.
# AUTHENTICATION_BACKENDS = AUTHENTICATION_BACKENDS + (
# 'django_auth_ldap.backend.LDAPBackend',
# )
# To be able to create projects/teams, is_superuser flag is needed.
# AUTH_LDAP_USER_FLAGS_BY_GROUP = {
# "is_active": "cn=active,ou=Group,dc=example,dc=com",
# "is_staff": "cn=staff,ou=Group,dc=example,dc=com",
# "is_superuser": "cn=superuser,ou=Group,dc=example,dc=com"
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment