from flask import current_app
from flask_httpauth import HTTPBasicAuth, HTTPDigestAuth
from werkzeug.security import safe_str_cmp
basicauth = HTTPBasicAuth()
httpauth = HTTPDigestAuth()
@httpauth.get_password
def get_pw(username):
if username in current_app.config["HTTP_DIGEST_AUTH_USERS"]:
return current_app.config["HTTP_DIGEST_AUTH_USERS"][username]
return None
@basicauth.verify_password
def verify_password(username, password):
if username in current_app.config["HTTP_DIGEST_AUTH_USERS"]:
return safe_str_cmp(
current_app.config["HTTP_DIGEST_AUTH_USERS"][username], password
)
return None