Django Auth

We are successfully using Active Directory in a project.


To login when using the development server (i.e. no IIS server to do the authentication, set the REMOTE_USER environment variable e.g. (for the fish shell):

set -x REMOTE_USER "patrick.kimber"

For more information see StackOverflow, using REMOTE_USER - How to test in dev server


We created our own authentication_backend:

# -*- encoding: utf-8 -*-
from django.contrib.auth.backends import RemoteUserBackend

class ExistingRemoteUserBackend(RemoteUserBackend):

    create_unknown_user = False

    def clean_username(self, username):
        """Remove the domain name from the 'username'."""
        pos = username.find("\\")
        if pos == -1:
            result = username
            result = username[pos + 1 :]
        return result

Our tests are copies of the Django tests at test_remote_user.