Created
October 27, 2020 09:27
-
-
Save gonzalo123/faabe2162b6343b267018d792a1b2c28 to your computer and use it in GitHub Desktop.
flask Autorization Bearer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
from flask import request, abort | |
from lib.logger import logger | |
def authorize_bearer(bearer): | |
def authorize(f): | |
@wraps(f) | |
def decorated_function(*args, **kws): | |
if 'Authorization' not in request.headers: | |
logger.error("Unauthorized") | |
abort(401) | |
data = request.headers['Authorization'] | |
if str.replace(str(data), 'Bearer ', '') != bearer: | |
abort(401) | |
return f(*args, **kws) | |
return decorated_function | |
return authorize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment