decorators.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:discovery 作者: lyft 项目源码 文件源码
def basic_authenticate(f):
    @wraps(f)
    def decorated(*args, **kwargs):

        if not current_app.config.get("USE_AUTH"):
            return f(*args, **kwargs)

        if not getattr(f, 'basic_authenticate', True):
            return f(*args, **kwargs)

        auth = request.authorization

        if auth and auth.username and auth.password != '':
            password = current_app.config.get("{}_PASSWORD".format(auth.username.upper()))

            if auth.password == password:
                role = AUTH_ROLES[auth.username]
                logging.debug("Authenticated '{}' with role '{}' via basic auth".format(auth.username, role))
                current_app.auth_role = role
                return f(*args, **kwargs)

        return abort(401)
    return decorated
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号