browser-go-api/api/decorators.py
2019-10-24 16:11:27 -07:00

21 lines
No EOL
682 B
Python

from flask import Blueprint, request, jsonify, session, abort
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:
auth_token = auth_header.split(" ")[1]
try:
if jwt.decode(auth_token, os.environ.get('SECRET_KEY')):
return func(*args, **kwargs)
else:
abort(401)
except:
abort(401)
else:
abort(401)
return authorized
return decorator