代码之家  ›  专栏  ›  技术社区  ›  Florian Bösch

将apache2摘要身份验证信息传递给mod_wsgi运行的wsgi脚本

  •  9
  • Florian Bösch  · 技术社区  · 18 年前

    我拿到指令了

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

    哪个用户登录了。

    我该怎么做?

    2 回复  |  直到 18 年前
        1
  •  15
  •   nosklo    18 年前

    添加 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 documentation .

        2
  •  2
  •   Graham Dumpleton    17 年前

    有关Apache/mod_wsgi以及访问、身份验证和授权机制的更多信息,请参阅:

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

    默认情况下不会传递信息,因为这样做可能会将密码信息泄露给可能不应该获取的应用程序。