LDAP Login Authentication Using Python LDAP

About 2 days ago, I have to create an app for internal company use. I'm using EmeraldBox to develop it. At first I created the user model to save user credentials and using it during the login process.

However, the boss came with an idea that I should use LDAP login since we have it and it provides a single sign-on solution, which is better.

So, I googled around and found python-ldap.

You can easily install it by running:
pip install python-ldap
and it's ready to use.

The question is, how can I use it?

Check out the code I use below for references. The steps should be the same. However, you need to adjust some values accordingly to the LDAP settings in the server.

It's as easy as that and you can perform login and get the user credentials. In my app, I use Flask's session to put the user credentials so I can fetch it whenever I need to.

Feel free to use my code.

Happy hacking!!!


regards

-E-

Comments

  1. import ldap
    conn = ldap.open("ldap.company.com")
    conn.simple_bind_s("myuser@company.com", "mypassword")

    ReplyDelete
  2. i tried ur code but its throwing me the following error

    ldap.LDAPError: (2, 'No such file or directory')

    ReplyDelete
  3. here username and password means either ldap credentials or credentials of the user who logged in??????

    ReplyDelete
  4. It's as easy as that and you can perform login and get the user credentials. In my app, I use Flask's session to put the user credentials so I can fetch it whenever I need to.

    ReplyDelete
  5. Thanks, for your blog but i m getting error :
    Exception{'info': '80090308: LdapErr: DSID-0C0903A9, comment: AcceptSecurityContext error, data 52e, v1db1', 'desc': 'Invalid credentials'}

    ReplyDelete
    Replies
    1. you account or password is error, or you account has a domain

      Delete

Post a Comment

Popular posts from this blog

Customizing Sanic's Logging output on Gunicorn

5 Takeaways From My Past 5 Years With Coral, Prism, Midtrans and Gojek

Lessons From Leading and Developing Product Engineering Teams - Part 1