将apache2摘要身份验证信息传递给由mod_wsgi运行的wsgi脚本
时间:2020-03-06 14:37:25 来源:igfitidea点击:
我有指令
<VirtualHost *> <Location /> AuthType Digest AuthName "global" AuthDigestDomain / AuthUserFile /root/apache_users <Limit GET> Require valid-user </Limit> </Location> WSGIScriptAlias / /some/script.wsgi WSGIDaemonProcess mywsgi user=someuser group=somegroup processes=2 threads=25 WSGIProcessGroup mywsgi ServerName some.example.org </VirtualHost>
我想在/some/script.wsgi中知道
def application(environ, start_response): start_response('200 OK', [ ('Content-Type', 'text/plain'), ]) return ['Hello']
什么用户已登录。
我怎么做?
解决方案
添加WSGIPassAuthorization On
:
<VirtualHost *> <Location /> AuthType Digest AuthName "global" AuthDigestDomain / AuthUserFile /root/apache_users <Limit GET> Require valid-user </Limit> </Location> WSGIPassAuthorization On WSGIScriptAlias / /some/script.wsgi WSGIDaemonProcess mywsgi user=someuser group=somegroup processes=2 threads=25 WSGIProcessGroup mywsgi ServerName some.example.org </VirtualHost>
然后只需阅读environ ['REMOTE_USER']
:
def application(environ, start_response): start_response('200 OK', [ ('Content-Type', 'text/plain'), ]) return ['Hello %s' % environ['REMOTE_USER']]
有关更多信息,请参见mod_wsgi文档。
有关Apache / mod_wsgi以及访问,身份验证和授权机制的其他信息,可以在以下位置找到:
http://code.google.com/p/modwsgi/wiki/AccessControlMechanisms
默认情况下不会传递该信息,因为这样做可能会将密码信息泄漏给可能不应该获取的应用程序。