{"id":16154948,"url":"https://github.com/rroemhild/flask-ldapconn","last_synced_at":"2025-04-07T19:17:07.843Z","repository":{"id":26751770,"uuid":"30209581","full_name":"rroemhild/flask-ldapconn","owner":"rroemhild","description":"Flask extension providing python-ldap3 connection and ORM for accessing LDAP servers.","archived":false,"fork":false,"pushed_at":"2024-07-06T02:02:18.000Z","size":257,"stargazers_count":64,"open_issues_count":14,"forks_count":33,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-01T22:13:24.702Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rroemhild.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-02-02T21:28:20.000Z","updated_at":"2024-05-22T14:20:34.000Z","dependencies_parsed_at":"2024-01-31T10:48:11.115Z","dependency_job_id":"270ac1f6-2ee3-4c81-958a-07a3493100a7","html_url":"https://github.com/rroemhild/flask-ldapconn","commit_stats":{"total_commits":143,"total_committers":11,"mean_commits":13.0,"dds":"0.19580419580419584","last_synced_commit":"46bf8ed2cfa0799a0ceb39ff2c3100321f6471c8"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rroemhild%2Fflask-ldapconn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rroemhild%2Fflask-ldapconn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rroemhild%2Fflask-ldapconn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rroemhild%2Fflask-ldapconn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rroemhild","download_url":"https://codeload.github.com/rroemhild/flask-ldapconn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247713258,"owners_count":20983683,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T01:19:20.363Z","updated_at":"2025-04-07T19:17:07.810Z","avatar_url":"https://github.com/rroemhild.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Flask-LDAPConn\n==============\n\n.. image:: https://travis-ci.org/rroemhild/flask-ldapconn.svg?branch=master\n    :target: https://travis-ci.org/rroemhild/flask-ldapconn\n\n.. image:: https://badge.fury.io/py/Flask-LDAPConn.svg\n    :target: https://badge.fury.io/py/Flask-LDAPConn\n\nFlask-LDAPConn is a Flask extension providing `ldap3 \u003chttps://github.com/cannatag/ldap3\u003e`_ (an LDAP V3 pure Python client) connection for accessing LDAP servers.\n\nTo abstract access to LDAP data this extension provides a simple ORM model.\n\n\nInstallation\n------------\n\n.. code-block:: shell\n\n    pip install flask-ldapconn\n\n\nConfiguration\n-------------\n\nYour configuration should be declared within your Flask config. Sample configuration:\n\n.. code-block:: python\n\n    import ssl\n\n    LDAP_SERVER = 'localhost'\n    LDAP_PORT = 389\n    LDAP_BINDDN = 'cn=admin,dc=example,dc=com'\n    LDAP_SECRET = 'forty-two'\n    LDAP_CONNECT_TIMEOUT = 10  # Honored when the TCP connection is being established\n    LDAP_USE_TLS = True  # default\n    LDAP_REQUIRE_CERT = ssl.CERT_NONE  # default: CERT_REQUIRED\n    LDAP_TLS_VERSION = ssl.PROTOCOL_TLSv1_2  # default: PROTOCOL_TLSv1\n    LDAP_CERT_PATH = '/etc/openldap/certs'\n\nIf you want to always get any entry attribute value as a list, instead of a string if only one item is in the attribute list, then set:\n\n.. code-block:: python\n\n    FORCE_ATTRIBUTE_VALUE_AS_LIST = True\n\nDefault is ``False`` and will return a string if only one item is in the attribute list.\n\n\nSetup\n-----\n\nCreate the LDAP instance in your application.\n\n.. code-block:: python\n\n    from flask import Flask\n    from flask_ldapconn import LDAPConn\n\n    app = Flask(__name__)\n    ldap = LDAPConn(app)\n\n\nClient sample\n-------------\n\n.. code-block:: python\n\n    from flask import Flask\n    from flask_ldapconn import LDAPConn\n    from ldap3 import SUBTREE\n\n    app = Flask(__name__)\n    ldap = LDAPConn(app)\n\n    @app.route('/')\n    def index():\n        ldapc = ldap.connection\n        basedn = 'ou=people,dc=example,dc=com'\n        search_filter = '(objectClass=posixAccount)'\n        attributes = ['sn', 'givenName', 'uid', 'mail']\n        ldapc.search(basedn, search_filter, SUBTREE,\n                     attributes=attributes)\n        response = ldapc.response\n\n\nUser model samples\n------------------\n\n.. code-block:: python\n\n    from flask import Flask\n    from flask_ldapconn import LDAPConn\n\n    app = Flask(__name__)\n    ldap = LDAPConn(app)\n\n    class User(ldap.Entry):\n\n        base_dn = 'ou=people,dc=example,dc=com'\n        object_classes = ['inetOrgPerson']\n\n        name = ldap.Attribute('cn')\n        email = ldap.Attribute('mail')\n        userid = ldap.Attribute('uid')\n        surname = ldap.Attribute('sn')\n        givenname = ldap.Attribute('givenName')\n\n    with app.app_context():\n\n        # get a list of entries\n        entries = User.query.filter('email: *@example.com').all()\n        for entry in entries:\n            print u'Name: {}'.format(entry.name)\n\n        # get the first entry\n        user = User.query.filter('userid: user1').first()\n\n        # new entry\n        new_user = User(\n            name='User Three',\n            email='user3@example.com',\n            userid='user3',\n            surname='Three',\n            givenname='User'\n        )\n        new_user.save()\n\n        # modify entry\n        mod_user = User.query.filter('userid: user1').first()\n        mod_user.name = 'User Number Three'\n        mod_user.email.append.('u.three@example.com')\n        mod_user.givenname.delete()\n        mod_user.save()\n\n        # remove entry\n        rm_user = User.query.filter('userid: user1').first()\n        rm_user.delete()\n\n        # authenticate user\n        auth_user = User.query.filter('userid: user1').first()\n        if auth_user:\n            if auth_user.authenticate('password1234'):\n                print('Authenticated')\n            else:\n                print('Wrong password')\n\n\nAuthenticate with Client\n------------------------\n\n.. code-block:: python\n\n    from flask import Flask\n    from flask_ldapconn import LDAPConn\n\n    app = Flask(__name__)\n    ldap = LDAPConn(app)\n\n    username = 'user1'\n    password = 'userpass'\n    attribute = 'uid'\n    search_filter = ('(active=1)')\n\n    with app.app_context():\n        retval = ldap.authenticate(username, password, attribute,\n                                   basedn, search_filter)\n        if not retval:\n            return 'Invalid credentials.'\n        return 'Welcome %s.' % username\n\n\nBind as user\n------------\n\nTo bind as user for the current request instance a new connection from ``flask.g.ldap_conn``:\n\n.. code-block:: python\n\n    g.ldap_conn = ldap.connect(userdn, password)\n    user = User.query.get(userdn)\n\n\nUnit Test\n---------\n\nI use a simple Docker image to run the tests on localhost. The test file ``test_flask_ldapconn.py`` tries to handle ``start`` and ``stop`` of the docker container:\n\n.. code-block:: shell\n\n    pip install docker-py\n    docker pull rroemhild/test-openldap\n    python test_flask_ldapconn.py\n\nRun the docker container manual:\n\n.. code-block:: shell\n\n    docker run --privileged -d -p 389:389 --name flask_ldapconn rroemhild/test-openldap\n    DOCKER_RUN=False python test_flask_ldapconn.py\n\nUnit test with your own settings from a file:\n\n.. code-block:: shell\n\n    LDAP_SETTINGS=my_settings.py python test_flask_ldapconn.py\n\n\nContribute\n----------\n\n#. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.\n#. Fork `the repository`_ on Github to start making your changes.\n#. Write a test which shows that the bug was fixed or that the feature works as expected.\n#. Send a pull request and bug the maintainer until it gets merged and published.\n\n.. _`the repository`: http://github.com/rroemhild/flask-ldapconn\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frroemhild%2Fflask-ldapconn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frroemhild%2Fflask-ldapconn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frroemhild%2Fflask-ldapconn/lists"}