Skip to main content

Basic LDAP connection for Flask Applications

Project description

Flask-LDAPConn is a Flask extension providing python-ldap connection object for accessing LDAP servers.

Installation

pip install flask-ldapconn

Configuration

Your configuration should be declared within your Flask config. Sample configuration:

LDAP_URI = 'ldap://localhost:389'
LDAP_BINDDN = 'cn=admin,dc=example,dc=com'
LDAP_SECRET = 'forty-two'
LDAP_TIMEOUT = 10
LDAP_USE_TLS = True
LDAP_USE_SSL = False
LDAP_REQUIRE_CERT = False
LDAP_CERT_PATH = '/etc/openldap/certs'

To create the ldap instance within your application

from flask import Flask
from flask_ldapconn import LDAPConn

app = Flask(__name__)
ldap_conn = LDAPConn(app)

or

from flask import Flask
from flask_ldapconn import LDAPConn

ldap_conn = LDAPConn()

def create_app():
    app = Flask(__name__)
    ldap_conn.init_app(app)
    return app

Usage

from ldap import SCOPE_SUBTREE
from app import ldap_conn

@app.route('/')
def index():
    basedn = 'ou=people,dc=example,dc=com'
    searchfilter = '(objectClass=posixAccount)'
    attrs = ['sn', 'givenName', 'uid', 'mail']
    result = ldap_conn.connection.search_s(basedn, SCOPE_SUBTREE,
                                           search_filter, attrs)

Contribute

  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug. There is a Contributor Friendly tag for issues that should be ideal for people who are not very familiar with the codebase yet.

  2. Fork the repository on Github to start making your changes to the master branch (or branch off of it).

  3. Write a test which shows that the bug was fixed or that the feature works as expected.

  4. Send a pull request and bug the maintainer until it gets merged and published.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Flask-LDAPConn-0.1.tar.gz (3.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page