Files @ e7524377edcb
Branch filter:

Location: C3L-NOC/spaceapi/spaceapi/auth.py

Dennis Fink
werkzeug.security doesn't have a safe_str_cmp anymore. Use hmac implementation instead.
from hmac import compare_digest

from flask import current_app
from flask_httpauth import HTTPBasicAuth, HTTPDigestAuth

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 compare_digest(
            current_app.config["HTTP_DIGEST_AUTH_USERS"][username], password
        )
    return None