Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask - Active Directory Authentication [closed]

Tags:

flask

I made a small Flask application and I would like users to be able to authenticate with their Windows NT IDs. I am not a part of the IT team, so I have limited insight into this area and my IT team is not experienced with Python.

How easy would it be to configure this? I tried to do some Googling and I saw LDAP modules and Flask-Security. I am hoping for a quick guide or to be pointed into a specific direction.

  • There is an existing Active Directory and a lot of our internal websites use NT authentication
  • I made a Flask app that I will be porting to our internal network
  • I want users to be able to login to the site with their NT ID
  • I need to know what information I need (an LDAP server and port?) or what I need to do with IT to get this configured properly without breaking any security protocols

Thanks!

like image 762
trench Avatar asked Jan 16 '17 20:01

trench


2 Answers

It is quite easy to work with Flask as it is a lightweight and plugin-based Python web framework.

Things you will need for LDAP Configuration

  • LDAP Host
  • LDAP Domain
  • LDAP Profile Key

You need to install Flask-LDAP plugin

pip install Flask-LDAP 

and here is a basic example to get you started:

from flask import Flask from flask.ext.ldap import LDAP, login_required  app = Flask(__name__) app.debug = True  app.config['LDAP_HOST'] = 'ldap.example.com' app.config['LDAP_DOMAIN'] = 'example.com' app.config['LDAP_SEARCH_BASE'] = 'OU=Domain Users,DC=example,DC=com'  ldap = LDAP(app) app.secret_key = "welfhwdlhwdlfhwelfhwlehfwlehfelwehflwefwlehflwefhlwefhlewjfhwelfjhweflhweflhwel" app.add_url_rule('/login', 'login', ldap.login, methods=['GET', 'POST'])  @app.route('/') @ldap.login_required def index():     pass  # @app.route('/login', methods=['GET', 'POST']) # def login(): #     pass  if __name__ == '__main__': app.run(debug=True, host="0.0.0.0") 

More details can be found here

like image 155
Priyank Mehta Avatar answered Sep 30 '22 20:09

Priyank Mehta


For Name: Flask-LDAP, Version: 0.1.6 use this:

To install: pip install Flask-LDAP

and import by:

from flask import Flask from flask_ldap import LDAP, login_required 

then follow along Priyank's example.

like image 45
Yash Nag Avatar answered Sep 30 '22 21:09

Yash Nag