from functools import wraps from flask import request, jsonify, Blueprint, make_response auth_blueprint = Blueprint("auth", __name__) def check_auth(username, password): return True def requires_basic_auth(f): @wraps(f) def decorated(*args, **kwargs): auth = request.authorization if not auth or not check_auth(auth.username, auth.password): return jsonify({"message": "Could not verify"}), 401, {'WWW-Authenticate': 'Basic realm="Login Required"'} return f(auth.username,auth.password, *args, **kwargs) return decorated def check_login(username, password): return jsonify({"auth": "Success"})