Passing apache2 digest authentication information to a wsgi script run by mod_wsgi

寵の児 提交于 2019-12-01 02:15:25

问题


I've got the directive

<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>

I'd like to know in the /some/script.wsgi

def application(environ, start_response):
    start_response('200 OK', [
        ('Content-Type', 'text/plain'),
    ])
    return ['Hello']

What user is logged in.

How do I do that?


回答1:


add 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>

Then just read environ['REMOTE_USER']:

def application(environ, start_response):
    start_response('200 OK', [
        ('Content-Type', 'text/plain'),
    ])
    return ['Hello %s' % environ['REMOTE_USER']]

More information at mod_wsgi documentation.




回答2:


Additional information about Apache/mod_wsgi and access, authentication and authorization mechanisms can be found in:

http://code.google.com/p/modwsgi/wiki/AccessControlMechanisms

The information isn't passed by default because doing so could leak password information to applications which maybe shouldn't get it.



来源:https://stackoverflow.com/questions/123499/passing-apache2-digest-authentication-information-to-a-wsgi-script-run-by-mod-ws

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