Skip to content

Instantly share code, notes, and snippets.

@gonzalo123
Created October 27, 2020 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gonzalo123/faabe2162b6343b267018d792a1b2c28 to your computer and use it in GitHub Desktop.
Save gonzalo123/faabe2162b6343b267018d792a1b2c28 to your computer and use it in GitHub Desktop.
flask Autorization Bearer
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