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
|
2019-10-09 01:03:46 +00:00
|
|
|
|
|
|
|
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)
|
2019-10-09 01:03:46 +00:00
|
|
|
else:
|
|
|
|
abort(401)
|
|
|
|
return authorized
|
|
|
|
return decorator
|