Django REMOTE_USER does not exist but HTTP_REMOTE_

2019-06-08 04:01发布

All,

I have what should be a very simple problem. I am trying to use Django authentication using the REMOTE_USER variable following these instructions: https://docs.djangoproject.com/en/1.8/howto/auth-remote-user/.

Then, to test that this is working, I am using the postman chrome extension. There I am setting a header variable with the name "REMOTE-USER" and then text for a superuser, and then I'm hitting the django admin page. I don't automatically login.

I set a break point in the process_request function in the RemoteUserMiddleware class. When I make the request, I see that request.META["HTTP_REMOTE_USER"] exists but request.META["REMOTE_USER"] does not exist. The default RemoteUserMiddleware variable uses header="REMOTE_USER". It seems that HTTP Header variables gets a HTTP_ prefix, so I don't understand how this would ever work.

I feel like I must be missing something obvious. Thanks!

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-06-08 04:02

The REMOTE_USER is meant to be an environment variable set by your web server (e.g. Apache), not an HTTP header. If it was an HTTP header, then users would be able to spoof the header, and log in as any user they wanted.

All http headers are prefixed HTTP_ so that you can distinguish between them and environment variables.

You can set the environment variable with the development server as follows.

REMOTE_USER=admin ./manage.py runserver
查看更多
登录 后发表回答