You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
859 B

from quart import Response, request
from functools import wraps
from config import APP_PASSWORD, APP_USER
# Thanks flask examples
def check_auth(username, password):
"""This function is called to check if a username /
password combination is valid.
return username == APP_USER and password == APP_USER
def authenticate():
"""Sends a 401 response that enables basic auth"""
return Response(
'Could not verify your access level for that URL.\n'
'You have to login with proper credentials', 401,
{'WWW-Authenticate': 'Basic realm="Login Required"'})
def requires_auth(f):
def decorated(*args, **kwargs):
auth = request.authorization
if not auth or not check_auth(auth.username, auth.password):
return authenticate()
return f(*args, **kwargs)
return decorated