Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions flask_ldap_login/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@
update the application like::

app.config.update(LDAP={'URI': ..., })
:param URI:
Start by setting URI to point to your server.
The value of this setting can be anything that your LDAP library supports.
For instance, openldap may allow you to give a comma- or space-separated

:param URI:
Start by setting URI to point to your server.
The value of this setting can be anything that your LDAP library supports.
For instance, openldap may allow you to give a comma- or space-separated
list of URIs to try in sequence.

:param BIND_DN:
The distinguished name to use when binding to the LDAP server (with BIND_AUTH).
Use the empty string (the default) for an anonymous bind.
The distinguished name to use when binding to the LDAP server (with BIND_AUTH).
Use the empty string (the default) for an anonymous bind.

:param BIND_AUTH:
The password to use with BIND_DN

:param USER_SEARCH:
An dict that will locate a user in the directory.
The dict object may contain 'base' (required), 'filter' (required) and 'scope' (optional)
base: The base DN to search
filter: Should contain the placeholder %(username)s for the username.
scope:
scope:

e.g.::
{'base': 'dc=continuum,dc=io', 'filter': 'uid=%(username)s'}

:param KEY_MAP:
This is a dict mapping application context to ldap.
An application may expect user data to be consistent and not all ldap
setups use the same configuration::
'application_key': 'ldap_key'

'application_key': 'ldap_key'


"""
Expand All @@ -51,7 +51,7 @@

def scalar(value):
"""
Take return a value[0] if `value` is a list of length 1
Take return a value[0] if `value` is a list of length 1
"""
if isinstance(value, (list, tuple)) and len(value) == 1:
return value[0]
Expand Down Expand Up @@ -102,13 +102,13 @@ def format_results(self, results):

keymap = self.config.get('KEY_MAP')
if keymap:
return {key:scalar(userobj.get(value)) for key, value in keymap.items()}
return dict([(key,scalar(userobj.get(value))) for key, value in keymap.items()])
else:
return {key:scalar(value) for key, value in userobj.items()}
return dict([(key,scalar(value)) for key, value in userobj.items()])

def save_user(self, callback):
'''
This sets the callback for staving a user that has been looked up from from ldap.
This sets the callback for staving a user that has been looked up from from ldap.
The function you set should take a username (unicode) and and userdata (dict).

:param callback: The callback for retrieving a user object.
Expand All @@ -134,7 +134,7 @@ def attrlist(self):

def bind_search(self, username, password):
"""
Bind to BIND_DN/BIND_AUTH then search for user to perform lookup.
Bind to BIND_DN/BIND_AUTH then search for user to perform lookup.
"""

log.debug("Performing bind/search")
Expand Down Expand Up @@ -222,8 +222,8 @@ def connect(self):
def ldap_login(self, username, password):
"""
Authenticate a user using ldap. This will return a userdata dict
if successfull.
ldap_login will return None if the user does not exist or if the credentials are invalid
if successfull.
ldap_login will return None if the user does not exist or if the credentials are invalid
"""
self.connect()

Expand Down