【问题标题】:HTTP Basic auth using mod_wsgi [duplicate]使用 mod_wsgi 的 HTTP 基本身份验证 [重复]
【发布时间】:2012-11-02 20:20:33
【问题描述】:

我正在尝试使用我编写的以下装饰器对 bottle.py 进行 HTTP 基本身份验证:

def check_auth(username, password):
if username == 'admin' and password == 'pass':
    return True
else:
    return False

def authenticate(msg_string = "Authenticate."):
response.content_type = "application/json"
message = {'message': msg_string}
resp = jsonpickle.encode(message)
response.status = "401 - Unauthorized"
response.headers['WWW-Authenticate'] = 'Basic realm="PyBit"'

return resp

def requires_auth(f):
def decorated(*args, **kwargs):
    print request.auth
    auth = request.auth
    if not auth: 
        return authenticate()
    elif not check_auth(auth[0],auth[1]):
        response.status = "401 - Unauthorized"
        return authenticate("HTTP Authentication Failed.")
    else:
        return f(*args, **kwargs)
return decorated

它可以在内置的 wsgiref 服务器中工作,但当我使用 mod_wsgi 在 Apache 下运行我的应用程序时不能。在这种情况下,“auth”对象始终为“None”。

阿帕奇在捏它吗?

【问题讨论】:

    标签: python apache wsgi bottle


    【解决方案1】:

    没关系。排序它。默认情况下不传递授权标头。我们需要设置 WSGIPassAuthorization 指令来控制当等效的 HTTP 请求标头存在时,是否将 HTTP 授权标头传递给 WSGI 应用程序环境的 HTTP_AUTHORIZATION 变量中的 WSGI 应用程序。

    【讨论】:

    猜你喜欢
    • 2017-11-16
    • 1970-01-01
    • 2016-07-11
    • 1970-01-01
    • 2011-04-06
    • 2017-01-17
    • 2021-03-21
    • 2011-11-12
    • 2011-05-05
    相关资源
    最近更新 更多