Django REMOTE_USER does not exist but HTTP_REMOTE_USER does

≯℡__Kan透↙ 提交于 2019-12-23 03:11:17

问题


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:


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


来源:https://stackoverflow.com/questions/32508787/django-remote-user-does-not-exist-but-http-remote-user-does

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!