I am trying to do HTTP basic authentication with bottle.py using the following decorator I have written:
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
It works in the builtin wsgiref server, but not when I run my app under Apache using mod_wsgi. The "auth" object is always "None" in that case.
Is apache pinching it?