1

I'm trying to use multiple Authentication backends in Django 1.5.

I want to use RemoteUserBackend with a custom header and the standard ModelBackend

Seems like I can make one or the other work, but not both. If I try to log in using ModelBackend i get this error:

"'CustomHeaderMiddleware' object has no attribute 'authenticate'" 

settings.py:

MIDDLEWARE_CLASSES = (
    ...
    'myapp.backends.custom_auth.CustomHeaderMiddleware',
    ...
)

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'django.contrib.auth.backends.RemoteUserBackend',
    'myapp.backends.custom_auth.CustomHeaderMiddleware',
)

custom_auth.py:

from django.contrib.auth.middleware import RemoteUserMiddleware

class CustomHeaderMiddleware(RemoteUserMiddleware):
    header = "CUSTOM_USERID"

I'm not sure what I'm missing. It works if I set the 'CUSTOM_USERID', but I can't use the standard login.

What am I missing?

Rob L
  • 3,634
  • 2
  • 19
  • 38

1 Answers1

0

Remove 'myapp.backends.custom_auth.CustomHeaderMiddleware' from AUTHENTICATION_BACKENDS.

Also make sure 'django.contrib.auth.middleware.AuthenticationMiddleware', is before 'myapp.backends.custom_auth.CustomHeaderMiddleware' in MIDDLEWARE_CLASSES

Example:

MIDDLEWARE_CLASSES = (
    ...
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'myapp.backends.custom_auth.CustomHeaderMiddleware',
    ...
)

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'django.contrib.auth.backends.RemoteUserBackend',
)
Dev Mehta
  • 11
  • 2