How to access Apache Basic Authentication user in Flask

前端 未结 2 795
无人共我
无人共我 2021-02-20 06:08

I\'m developing a web page using Flask, on an Apache server where the Server is enforcing basic authentication. That is, a user accessing a page on the server is presented with

2条回答
  •  长情又很酷
    2021-02-20 06:38

    You can find authentication information in Flask from the request object.

    from flask import request
    
    def my_view():
        auth = request.authentication
        username = auth.username
        password = auth.password
        ...
    

    Note however that if you're using apache mod_wsgi, you'll need to turn on the WSGIPassAuthorization directive in your virtualhost config. Otherwise apache will consume the authentication header and won't pass it to the WSGI layers.

    
        ...
    
        WSGIPassAuthorization On
    
        ...
    
    

    more info here and here.

提交回复
热议问题