mod_python, user missing

K

KasiKuula

apache conf
<Directory /python-publisher/>
SetHandler mod_python
PythonHandler mod_python.publisher
</Directory>


and this is in /python-publisher/index.py

__auth_realm__ = 'VIP'

def __auth__(req, user, passwd):
if user == 'noppa' and passwd == 'potti':
return True
else:
return False

def __access__(req, user):
if user == 'noppa':
return True
else:
return False

def index(req):
req.get_basic_auth_pw()
user = req.user
return 'user is %s' % (user)


So problem is, how I get user in index function? That gives allways "None"
 
G

grahamd

Good question, according to the documentation it should work, I'll
push this onto the mod_python mailing list for discussion and get a
bug report posted if necessary.

In the meantime, you could use the following work around:

def __auth__(req, user, passwd):
req.user = user
if user == 'noppa' and passwd == 'potti':
return True
else:
return False

Ie., explicitly set "req.user" in the __auth__ method.
 
G

grahamd

Okay, reason it doesn't work is that req.get_basic_auth_pw() only
applies when using Apache itself to perform the user authentication.
Ie., where in Apache configuration files you have something like:

AuthType Basic
AuthName "VIP"
AuthUserFile /tmp/pwdb
Require user noppa

It doesn't work when using mod_python.publisher style authentication
as that is done in mod_python and not by Apache. Thus, you would
need to assign to req.user in the __auth__ method as I described to
have it so it is accessible in the published method. You will not need
to call the req.get_basic_auth_pw() function.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,228
Messages
2,571,157
Members
47,785
Latest member
deepusaini

Latest Threads

Top