Since keeping multiple authentication databases in sync is a common problem when dealing with Apache, you can configuring Apache to authenticate against Django’s authentication system directly. This requires Apache version >= 2.2 and mod_wsgi >= 2.0. For example, you could:
To check against Django’s authorization database from a Apache configuration file, you’ll need to set ‘wsgi’ as the value of AuthBasicProvider or AuthDigestProvider directive and then use the WSGIAuthUserScript directive to set the path to your authentification script:
<Location /example/>
AuthType Basic
AuthName "example.com"
AuthBasicProvider wsgi
WSGIAuthUserScript /usr/local/wsgi/scripts/auth.wsgi
Require valid-user
</Location>
Your auth.wsgi script will have to implement either a check_password(environ, user, password) function (for AuthBasicProvider) or a get_realm_hash(environ, user, realm) function (for AuthDigestProvider).
See the mod_wsgi documentation for more details about the implementation of such a solution.
May 20, 2012