ktv-python/routes/auth.py
2025-05-10 13:58:58 +01:00

25 lines
634 B
Python

from functools import wraps
from flask import request, Response
from lib.get_users import get_users
users = get_users()
def check_auth(username, password):
return users.get(username) == password
def authenticate():
return Response(
'Could not verify your access.\n',
401,
{'WWW-Authenticate': 'Basic realm="Login Required"'}
)
def requires_auth(f):
@wraps(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