Skip to navigation
How to login into a tornado webapp with the windows active directory credentials
14.06.17
#!/usr/bin/env python import os import tornado.escape import tornado.ioloop import tornado.options import tornado.web import tornado.websocket import os.path import controllers import datetime from tornado.options import define, options from pycket.session import SessionMixin from ldap3 import Server, Connection, SIMPLE, SYNC, ASYNC, SUBTREE, ALL class Logins(tornado.web.RequestHandler,SessionMixin): def get(self): self.redirect("/") def post(self): user = self.get_argument('username') passw = self.get_argument('password') if(len(user.strip()) and len(passw.strip())): try: s = Server('foo.bar.com',port = 389,get_info=ALL) c = Connection(s, auto_bind = True, client_strategy = SYNC, user=user.strip(), password=passw.strip(), authentication=SIMPLE, check_names=True) self.session.set('user_logged',True) self.redirect('/hubs',permanent=False) except Exception as e: print(e) else: #self.redirect('/logins',permanent=True) pass
http://ldap3.readthedocs.io/
Reply
Anonymous
Information Epoch 1766973393
Design for simplicity, add complexity only where you must.
Home
Notebook
Contact us