I have a website where only registered user can login and view documents, right now the documents are served through apache and can be viewed directly without login if you have the URL. I would like to protect those folder using Django Authentication, I have bee trying to do that but without any success :

httpd.conf:

```
WSGIScriptAlias / /home/www/wsgi-scripts/mysite.wsgi

<Directory /home/www/wsgi-scripts>
Order allow,deny
Allow from all
</Directory>

<Location /media/protected>
AuthType Basic
AuthName "Authentication Required"
AuthBasicProvider wsgi
WSGIAuthUserScript /home/www/wsgi-scripts/auth.wsgi
Require valid-user
</Location>  

```

auth.wsgi:

```
import os, sys
os.environ['PYTHON_EGG_CACHE'] = '/tmp'
apache_configuration= os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
sys.path.append('/usr/lib/python2.4/site-packages/django/')
sys.path.append('/home/www')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

from django.contrib.auth.models import User
from django import db
import threading 
cache = threading.local() 

def check_password(environ, username, password): 
    cache.username = None 
    cache.permissions = [''] 
    db.reset_queries() 
    kwargs = {'username': username, 'is_active': True} 
    try: 
        try: 
            user = User.objects.get(**kwargs) 
        except User.DoesNotExist: 
            return None 
        if user.check_password(password): 
            cache.username = username 
            cache.permissions = user.get_group_permissions() 
            return True 
        else: 
            return False 
    finally: 
        db.connection.close()

```

Anything I m doing wrong ?

Thks