python - WebService with Tornado.web and Authentication. Do you have Example? -
i'm brand new in tornado.web.
i write webservice in python tornado. consumed desktop application. want require application communicates after being authenticated.
i searched examples, can't found applicable case.
you add @tornado.web.authenticated
decorator, , specify application login url
specify debug=true
settings = dict({ "template_path": os.path.join(os.path.dirname(__file__),"templates"), "static_path": os.path.join(os.path.dirname(__file__),"static"), "cookie_secret": "make harde guess ;) ", "xsrf_cookies": true, "debug": false, "gzip": true, "login_url": "/#login", "site_url":"http://localhost:8000", })
and finally, inherit classes 1 controls cookies existance:
class basehandler(tornado.web.requesthandler): @tornado.web.removeslash def get_current_user(self): return self.get_secure_cookie("name_of_your_cookie")
example:
class test(basehandler): @tornado.web.authenticated def post(self): user = self.get_secure_cookie("name_of_your_cookie") # rest of code...
what happens now, everytime tries enter link use test
, application if cookie
exists, else, redirected login_url
Comments
Post a Comment