Friday, October 14, 2011

How to set up web2py + ldap with Windows Active Directory

This is a recipe to use web2py + ldap in the real world.

Install python-ldap
1. Download and install  python-ldap (e.g. python-ldap-2.4.3.win32-py2.7)

Edit models/
2. edit auth.define_tables() to allow login with username and not email.


3. Add the following at the bottom of page.
Replace server and base_dn to your setting.

# all we need is login

# you don't have to remember me
auth.settings.remember_me_form = False

# ldap authentication and not save password on web2py
from gluon.contrib.login_methods.ldap_auth import ldap_auth
auth.settings.login_methods = [ldap_auth(mode='ad',

4. Result


  1. This was a really great tutorial.
    How easy when knowing what to do.

    Regards Falk

  2. I just want to add that if you are using 1.99.4 this won't work. It's not due to anything wrong with the instructions, it's a bug. There's a fix for it here.

    1. @Derek - that fix did not work for me.

  3. Derek,

    Thank you for the comment. Yes I maded the fix :)
    1.99.6 will be released next few weeks which includes this patch so we will be fine.

  4. I am a newbie. I followed these instructions and I am not getting the login form. where do I add that ?

  5. ldap online training| ldap training| call us+919000444287 ...
    ఈ పేజీని అనువదించు
    LDAP Online Training, LDAP training, LDAP course contents, LDAP , call us: +919000444287,
    course contents, biztalk admin enquiry, ...Courses at 21st Century Software Solutions
    Talend Online Training -Hyperion Online Training - IBM Unica Online Training -
    Siteminder Online Training - SharePoint Online Training - Informatica Online Training
    SalesForce Online Training - Many more… | Call Us +917386622889

  6. This comment has been removed by the author.