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:
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-
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-ldapand 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-
import ldap
ReplyDeleteconn = ldap.open("ldap.company.com")
conn.simple_bind_s("myuser@company.com", "mypassword")
i tried ur code but its throwing me the following error
ReplyDeleteldap.LDAPError: (2, 'No such file or directory')
here username and password means either ldap credentials or credentials of the user who logged in??????
ReplyDeleteIt'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.
ReplyDeleteThanks, for your blog but i m getting error :
ReplyDeleteException{'info': '80090308: LdapErr: DSID-0C0903A9, comment: AcceptSecurityContext error, data 52e, v1db1', 'desc': 'Invalid credentials'}
you account or password is error, or you account has a domain
Delete