Add AuthenticatedHandler base class
This commit is contained in:
parent
b161d0d7e9
commit
b7836163ef
1 changed files with 20 additions and 0 deletions
20
app.py
20
app.py
|
@ -18,6 +18,26 @@ from gitmgr import GitManagerConfiguration, GitManager
|
||||||
startup_timestamp = datetime.now()
|
startup_timestamp = datetime.now()
|
||||||
|
|
||||||
|
|
||||||
|
class AuthenticatedHandler(tornado.web.RequestHandler, metaclass=ABCMeta):
|
||||||
|
# noinspection PyAttributeOutsideInit
|
||||||
|
def initialize(self, auth_provider=None):
|
||||||
|
self.auth_provider = auth_provider
|
||||||
|
|
||||||
|
def prepare(self):
|
||||||
|
if self.auth_provider is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
# check authentication
|
||||||
|
auth_hdr = "Authentication"
|
||||||
|
if auth_hdr not in self.request.headers:
|
||||||
|
raise tornado.web.HTTPError(401, reason="authentication not provided")
|
||||||
|
|
||||||
|
tk = self.request.headers[auth_hdr]
|
||||||
|
|
||||||
|
if not self.auth_provider.validate_token(tk):
|
||||||
|
raise tornado.web.HTTPError(403, reason="invalid authentication token provided")
|
||||||
|
|
||||||
|
|
||||||
class HealthHandler(tornado.web.RequestHandler, metaclass=ABCMeta):
|
class HealthHandler(tornado.web.RequestHandler, metaclass=ABCMeta):
|
||||||
# noinspection PyAttributeOutsideInit
|
# noinspection PyAttributeOutsideInit
|
||||||
def initialize(self, sources=None):
|
def initialize(self, sources=None):
|
||||||
|
|
Loading…
Reference in a new issue