Python flask_httpauth 模块,HTTPBasicAuth() 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用flask_httpauth.HTTPBasicAuth()

项目:msg    作者:lily-mayfield    | 项目源码 | 文件源码
def get_password(username, password):
    """For HTTPBasicAuth; this simply gets the
    corresponding user, then return the result
    of checking that password.

    Arguments:
        username (str):
        password (str):

    See Also:
        flask_httpauth

    Returns:
        bool: True if the password is correct for the supplied
            username, False otherwise.

    """

    result = (db.session.query(models.User)
              .filter(models.User.username == username).first())

    if result is None:
        return False
    else:
        return result.check_password(password)
项目:Rexy    作者:kasramvd    | 项目源码 | 文件源码
def gen_auth(self):
        return HTTPBasicAuth()
项目:FlaskService    作者:b96705008    | 项目源码 | 文件源码
def configure_auth(app, config):
    auth = HTTPBasicAuth()

    @auth.get_password
    def get_password(username):
        # fetch pwd from db
        if username == 'root':
            return '1234'
        return None

    @auth.error_handler
    def unauthorized():
        return make_response(jsonify({'error': 'Unauthorized access'}), 401)

    return auth