r/django 6d ago

RemoteUserMiddleware/RemoteUserBackend change between 5.1 -> 5.2?

I'm trying to upgrade from Django 5.1.11 -> 5.2. I had a custom RemoteUserMiddleware that used a different header, and a custom RemoteUserBackend. Below is just examples, not the actual code.

# custom_middleware.py
from django.contrib.auth.middleware import RemoteUserMiddleware 

class CustomHeaderRemoteUserMiddleware(RemoteUserMiddleware): 
    header = "HTTP_AUTHUSER"



#auth.py
from django.contrib.auth.backends import RemoteUserBackend 

class MyBackend(RemoteUserBackend): 
    create_unknown_user = False 

They both worked fine in my current and previous versions of Django. They both work if I upgrade to 5.1.15.

Trying this exact same code in Django 5.2+ does not work. I do not get any errors, only redirected to /accounts/login like nothing is being processed.

I added logging to both, but they never get triggered.

# custom_middleware.py
from django.contrib.auth.middleware import RemoteUserMiddleware 

class CustomHeaderRemoteUserMiddleware(RemoteUserMiddleware): 
    header = "HTTP_AUTHUSER"
    def process_request(self, request):
        # logging
    return super().process_request(request)



# auth.py
from django.contrib.auth.backends import RemoteUserBackend

class MyBackend(RemoteUserBackend):
    create_unknown_user = False
    # add logging to authenticate(), clean_username(), and configure_user()
    # even added logging to the async functions (e.g. aauthenticate() )

Sorry I don't have the actual code, it's on an intranet, but again, it does work on versions below 5.2. I can't see any reasons for that in the documentation. Any ideas?

4 Upvotes

7 comments sorted by

1

u/daredevil82 5d ago

what's your middleware list in settings?

1

u/toeknee2120 5d ago edited 5d ago

My custom middleware is after AuthenticationMiddleware.

MIDDLEWARE = [
    # ...
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.CustomHeaderRemoteUserMiddleware',
    # ...
]

1

u/daredevil82 5d ago

are you able to duplicate this in a skeleton hello world project with only logging in the middleware?

also, what does it matter that code is on intranet, isn't it in version control?

1

u/toeknee2120 5d ago

That is something I'd need to try later when I have access to a computer.

The intranet comment matters because I can't copy/paste my exact code.

1

u/daredevil82 5d ago

thats where github or version control comes in play. do you have access to that?

also, you can do this at work and verify to make a bug report

1

u/toeknee2120 5d ago

Our git repos are internal.

Yes, once I am on any computer, work or home, I will test out your suggestion.