I want to check if the user is authenticated before he/she can access the method, so I wrote a decorator named
authorize
@authorize
def post(self, **kw):
# store data in database after authentication done using @authorize
def authorize(f):
def wrapper(*args, **kwargs):
secret_key = config.get('auth_secret_key')
auth_message = config.get('auth_message')
if 'HTTP_TOKEN' not in request.environ:
abort(401, detail='Authentication failed', passthrough='json')
gibberish = request.environ['HTTP_TOKEN']
if triple_des(secret_key).decrypt(gibberish, padmode=2).decode() != auth_message:
abort(401, detail='Authentication failed', passthrough='json')
return wrapper
401
post
You need to actually call the function within your wrapper.
f(*args, **kwargs)