I have my ionic as frontend, which append a Bearer Token in each Request. My Tornado server is already configured for CORS. The problem is when I activate my decorator to check if that request has 'Authorization' header, I don't why, that header disappeared. There's no 'Authorization' header. But If I disable this header, everything is ok and tornado show me that header.
Any idea?
I override RequestHandler set_default_headers method
With these headers:
set_default_headers(self):
self.set_header("Access-Control-Allow-Origin", "*")
self.set_header("Access-Control-Allow-Headers", "authorization")
self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')
Decorator
class EvaluationHandler(RequestHandler)
def get(self):
print(handler.request.headers) <--- Good headers
My token decorator to check it:
def jwtauth(handler_class):
def wrap_execute(handler_execute):
def require_auth(handler, kwargs):
auth = handler.request.headers.get('Authorization', None)
print(handler.request.headers) <---- Bad Headers
print(auth)
if auth:
if not loginRepository.validToken(auth):
return_header_error(handler)
else:
return_header_error(handler)
handler._transforms = []
handler.write(MISSING_AUTHORIZATION_KEY)
handler.finish()
return True
def _execute(self, transforms, *args, **kwargs):
try:
require_auth(self, kwargs)
except Exception:
return False
return handler_execute(self, transforms, *args, **kwargs)
return _execute
handler_class._execute = wrap_execute(handler_class._execute)
return handler_class
EDIT: the problem could be custom decorator is taking is own header configuration, but I don't know how to do it anyway