title: SLL authenticate from apache in Django
body: <p>I want to authenticate a user using information from x509 certificate... 
  Apache seems to authenticate ok, but I get no REMOTE_USER content in Django. Don t know why.</p>
  
  <p>apache config:</p>
  
  <pre><code>NameVirtualHost *:443
  &lt;VirtualHost *:443&gt;
          SSLEngine On
          SSLCertificateFile    /etc/apache2/ssl/server.crt
          SSLCertificateKeyFile /etc/apache2/ssl/server.key
  
          SSLVerifyClient require
          SSLVerifyDepth 10
          SSLCACertificateFile /etc/apache2/ssl/ca.cer
  
  
          SSLOptions +StdEnvVars +ExportCertData
  
          &lt;Directory /&gt;
                          Options FollowSymLinks
                          AllowOverride None
                          SSLOptions +StdEnvVars
  
  
          &lt;/Directory&gt;
          &lt;Directory /var/www/&gt;
                          Options Indexes FollowSymLinks MultiViews
                          AllowOverride None
                          Order allow,deny
                          allow from all
          &lt;/Directory&gt;
          WSGIDaemonProcess rmc_wsgi processes=2 threads=15 display-name=%{GROUP}
          WSGIScriptAlias /rmc /home/xxx/projects/rmc/rmc/wsgi.py
          &lt;Location /rmc&gt;
                  WSGIProcessGroup rmc_wsgi
          &lt;/Location&gt;
  
  
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>Middleware:</p>
  
  <pre><code>class CorrectRemoteUserMiddleware(RemoteUserMiddleware):
      header = "HTTP_REMOTE_USER"
  </code></pre>
  
  <p>backend</p>
  
  <pre><code>class RemoteUserBackendNoCreate(RemoteUserBackend):
      create_unknown_user = True
  
      def authenticate(self, remote_user):
          user = super(self.__class__, self).authenticate(remote_user)
          print &gt;&gt; sys.stderr, ("AuthBackend: REMOTE_USER=" + remote_user + "AuthBackend: User=" + user)
          print &gt;&gt; sys.stderr, 'in authenticate'
          return user
  </code></pre>
  
  <p>settings.py:</p>
  
  <pre><code>MIDDLEWARE_CLASSES = (
      'django.contrib.sessions.middleware.SessionMiddleware',
      'django.middleware.common.CommonMiddleware',
      'django.middleware.csrf.CsrfViewMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'webrecif.middleware.CorrectRemoteUserMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
      'django.middleware.clickjacking.XFrameOptionsMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.contrib.auth.middleware.RemoteUserMiddleware',
  
  )
  
  AUTHENTICATION_BACKENDS = (
      'django.contrib.auth.backends.RemoteUserBackend',
      'webrecif.backends.RemoteUserBackendNoCreate',
  )
  
  TEMPLATE_CONTEXT_PROCESSORS = (
      'django.contrib.auth.context_processors.auth',
      'django.core.context_processors.static',
  )
  </code></pre>