browser-go-api/api/decorators.py

18 lines
590 B
Python
Raw Normal View History

2019-10-09 22:42:38 +00:00
from flask import Blueprint, request, jsonify, session, abort
2019-10-09 05:53:37 +00:00
import os
import jwt
def jwt_required():
def decorator(func):
def authorized(*args, **kwargs):
auth_header = request.headers.get('Authorization') or None
if auth_header:
2019-10-09 05:53:37 +00:00
auth_token = auth_header.split(" ")[1]
if jwt.decode(auth_token, os.environ.get('SECRET_KEY')):
return func(*args, **kwargs)
else:
abort(401)
else:
abort(401)
return authorized
return decorator