This question already has answers here:
Passing apache2 digest authentication information to a wsgi script run by mod_wsgi
(2个答案)
3年前关闭。
我正在尝试使用以下编写的装饰器对bottle.py进行HTTP基本身份验证:
它可以在内置的wsgiref服务器中工作,但是当我使用mod_wsgi在Apache下运行我的应用程序时,它就不能工作。在这种情况下,“ auth”对象始终为“ None”。
是Apache捏吗?
(2个答案)
3年前关闭。
我正在尝试使用以下编写的装饰器对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”。
是Apache捏吗?
最佳答案
没关系排序。默认情况下,不通过授权头。我们需要设置WSGIPassAuthorization指令,以在存在等效的HTTP请求标头时,控制是否在WSGI应用程序环境的HTTP_AUTHORIZATION变量中将HTTP授权标头传递给WSGI应用程序。