Edgewall Software

Changes between Version 44 and Version 45 of TracModPython


Ignore:
Timestamp:
Oct 1, 2005, 1:03:25 PM (19 years ago)
Author:
Lele Gaifax
Comment:

Recipe for Pythonic authentication

Legend:

Unmodified
Added
Removed
Modified
  • TracModPython

    v44 v45  
    105105}}}
    106106
     107== Virtual Host Configuration, Multiple Projects and Pythonic Authentication ==
     108
     109{{{
     110<VirtualHost *>
     111    ServerName projects.example.com
     112
     113    <Directory />
     114        SetHandler mod_python
     115        PythonHandler trac.web.modpython_frontend
     116        PythonOption TracEnvParentDir .../tracs
     117        PythonOption TracUriRoot /
     118    </Directory>
     119
     120    <LocationMatch "/[^/]+/login">
     121        AuthType Basic
     122        AuthName "Projects Trac Server"
     123        PythonAuthenHandler trac.projects
     124        Require valid-user
     125    </LocationMatch>
     126</VirtualHost>
     127}}}
     128
     129The `PythonAuthenHandler` introduces an object that will handle the actual authentication process, in this case `trac.projects` is the name of a module to import (and thus must be located somewhere in the Python load path).
     130In this example, I created `.../site-packages/trac/projects` that contains this little script called `__init__.py`:
     131
     132{{{
     133from mod_python import apache
     134
     135def authenhandler(req):
     136    pw = req.get_basic_auth_pw()
     137    user = req.user
     138    if user == "admin" and pw == "trac":
     139        return apache.OK
     140    else:
     141        return apache.HTTP_UNAUTHORIZED
     142}}}
     143
     144that of course is just a sample. The name `authenhandler` comes from the default behaviour of mod_python, but you may specify a different one using the syntax `trac.projects::my_own_handler`.
     145
    107146== Troubleshooting ==
    108147