Skip to content

Commit

Permalink
Merge branch 'release/1.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Apr 11, 2016
2 parents 292cba2 + fbf6a96 commit 87c5e0b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .env
Expand Up @@ -16,7 +16,7 @@ fi

export PROJECT_NAME=$OPEN_PROJECT_NAME
export PROJECT_DIR="$PWD"
export PROJECT_VERSION="1.0.2"
export PROJECT_VERSION="1.0.3"

if [ ! -d "venv" ]; then
if ! hash pyvenv 2>/dev/null; then
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,8 +1,11 @@
Changelog
=========
### 1.0.3
- Enable a string to be passed in as the server for the verify function

### 1.0.1 - 1.0.2
- Fixed README on PYPI page
- Fixed travis integration

### 1.0.0
- Initial Release
18 changes: 18 additions & 0 deletions README.md
Expand Up @@ -22,6 +22,24 @@ def say_hello(hug_user):
return 'Hello {}!'.format(hug_user.name)
```

Or, for general reusable LDAP password verification within hug:

```py
import hug
import hug_authentication_ldap


ldap_check = hug_authentication_ldap.verify('myldap.server.net', 'uid={user_name},ou=people')


@hug.get()
def check(user_name, password):
if ldap_check(user_name, password):
return True

return False
```

Installing hug_authentication_ldap
===================

Expand Down
2 changes: 1 addition & 1 deletion hug_authentication_ldap/_version.py
Expand Up @@ -19,4 +19,4 @@
OTHER DEALINGS IN THE SOFTWARE.
"""
current = "1.0.2"
current = "1.0.3"
7 changes: 5 additions & 2 deletions hug_authentication_ldap/authentication.py
Expand Up @@ -32,16 +32,19 @@ def server(url, get_info=ldap3.ALL, **kwargs):
return ldap3.Server(url, get_info=get_info, **kwargs)


def verify(server, user_template="uid={user_name},ou=people", authentication=ldap3.AUTH_SIMPLE, auto_bind=True,
def verify(server_instance, user_template="uid={user_name},ou=people", authentication=ldap3.AUTH_SIMPLE, auto_bind=True,
**kwargs):
"""Returns an authentication verification callback that enforces ldap authentication passing in the
user_template with the passed in user overriding any in-string placement of {user_name}
passes any extra **kwargs parameters to the ldap3.Connection method used for authentication
"""
if type(server_instance) == str:
server_instance = server(server_instance)

def verify_user(user_name, password):
try:
connection = ldap3.Connection(server, authentication=authentication, auto_bind=auto_bind,
connection = ldap3.Connection(server_instance, authentication=authentication, auto_bind=auto_bind,
user=user_template.format(user_name=user_name), password=password, **kwargs)
return user(user_name, connection)
except ldap3.core.exceptions.LDAPBindError:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -82,7 +82,7 @@ def run_tests(self):
readme = ''

setup(name='hug_authentication_ldap',
version='1.0.2',
version='1.0.3',
description='LDAP based authentication support for hug',
long_description=readme,
author='Timothy Crosley',
Expand Down

0 comments on commit 87c5e0b

Please sign in to comment.