diff --git a/.travis.yml b/.travis.yml index 78feec81ef2e4bcba5eb7b6007122b6533cbe51b..95851aff0c873cf86b45e891684fb94b2ae72386 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,12 +3,12 @@ sudo: required dist: xenial python: - "2.7" - - "3.4" - "3.5" - "3.6" - "3.7" env: - - FLASK=1.0.2 + - FLASK=1.1.1 + - FLASK=1.0.4 - FLASK=0.12.4 install: - pip install Flask==$FLASK diff --git a/LICENSE b/LICENSE index de96633cdd105841b63aa1caa9f45508001d77b1..89f8850e9d23f4145c26bef43f5684fb90214b09 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2017 Alexandre Ferland +Copyright (c) 2019 Alexandre Ferland Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 96dc713cc5e5b1ee042b7236cea321efd779b4d5..e00e9a38e7516f675e624a0f596b42c0143685bc 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ First, install Flask-SimpleLDAP: Flask-SimpleLDAP depends, and will install for you, recent versions of Flask (0.10.1 or later) and [pyldap](https://github.com/pyldap/pyldap). Flask-SimpleLDAP is compatible -with and tested on Python 2.7, 3.4, 3.5 and 3.6. +with and tested on Python 2.7, 3.5, 3.6 and 3.7. Next, add a ``LDAP`` instance to your code and at least the three required configuration options: @@ -30,10 +30,16 @@ app.config['LDAP_PASSWORD'] = 'password' ldap = LDAP(app) + @app.route('/ldap') @ldap.login_required def ldap_protected(): return 'Success!' + + +if __name__ == '__main__': + app.run() + ``` You can take a look at [examples/groups](examples/groups) for a more complete @@ -78,10 +84,16 @@ app.config['LDAP_GROUP_MEMBER_FILTER_FIELD'] = "cn" ldap = LDAP(app) + @app.route('/ldap') @ldap.login_required def ldap_protected(): return 'Success!' + + +if __name__ == '__main__': + app.run() + ``` diff --git a/flask_simpleldap/__init__.py b/flask_simpleldap/__init__.py index 9c83ade2f5de4dd42f8eab3d38af1e09b190a6a3..23b389c246ebbed86c5707a914c715316cca9bbf 100644 --- a/flask_simpleldap/__init__.py +++ b/flask_simpleldap/__init__.py @@ -75,9 +75,6 @@ class LDAP(object): if app.config['LDAP_{0}'.format(option)] is None: raise LDAPException('LDAP_{0} cannot be None!'.format(option)) - # Bind LDAP to app - app.ldap = self - @staticmethod def _set_custom_options(conn): options = current_app.config['LDAP_CUSTOM_OPTIONS'] @@ -175,13 +172,13 @@ class LDAP(object): if not dn_only: fields = current_app.config['LDAP_USER_FIELDS'] query_filter = query_filter or \ - current_app.config['LDAP_USER_OBJECT_FILTER'] + current_app.config['LDAP_USER_OBJECT_FILTER'] query = ldap_filter.filter_format(query_filter, (user,)) elif group is not None: if not dn_only: fields = current_app.config['LDAP_GROUP_FIELDS'] query_filter = query_filter or \ - current_app.config['LDAP_GROUP_OBJECT_FILTER'] + current_app.config['LDAP_GROUP_OBJECT_FILTER'] query = ldap_filter.filter_format(query_filter, (group,)) conn = self.bind try: @@ -201,9 +198,9 @@ class LDAP(object): current_app.config['LDAP_OBJECTS_DN']] return dn[0] if type(records[0][1]) == 'dict': - for k, v in list(records[0][1].items()): - result[k] = v - return result + for k, v in list(records[0][1].items()): + result[k] = v + return result except ldap.LDAPError as e: raise LDAPException(self.error(e.args)) diff --git a/run.py b/run.py new file mode 100644 index 0000000000000000000000000000000000000000..a6a54b5c6217e771258bd0d645e4736c7f957d7c --- /dev/null +++ b/run.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_simpleldap import LDAP + +app = Flask(__name__) +app.config['LDAP_BASE_DN'] = 'OU=users,dc=example,dc=org' +app.config['LDAP_USERNAME'] = 'CN=user,OU=Users,DC=example,DC=org' +app.config['LDAP_PASSWORD'] = 'password' + +ldap = LDAP(app) + + +@app.route('/ldap') +@ldap.login_required +def ldap_protected(): + return 'Success!' + + +if __name__ == '__main__': + app.run() + diff --git a/setup.py b/setup.py index 85c2314992d3f50bcb8ed6be5af85b98a119a50c..2f5d8dc0b2714bcf08299ded37b74085e08ae821 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ from setuptools import setup setup( name='Flask-SimpleLDAP', - version='1.2.0', + version='1.3.0', url='https://github.com/admiralobvious/flask-simpleldap', license='MIT', author='Alexandre Ferland', @@ -21,7 +21,7 @@ setup( include_package_data=True, platforms='any', install_requires=[ - 'Flask>=0.10.1', + 'Flask>=0.12.4', 'python-ldap' ], classifiers=[ @@ -33,6 +33,7 @@ setup( 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', 'Topic :: Software Development :: Libraries :: Python Modules' ] )