2016-12-31 66 views
2

我有一個nginx http服務器,它對用戶進行身份驗證,並通過wsgi將已驗證的請求傳遞給Flask應用程序。當我從燒瓶應用程序打印整個標題時,沒有用戶信息可用。如何配置nginx將用戶信息傳遞給wsgi/flask

是否有可能讓nginx在請求頭中包含用戶名?

下面是認證配置服務器塊...

server { 
    listen 80; 
    server_name notes.example.org; 
    return 301 https://$server_name$request_uri; 
} 

server { 


    # SSL configuration 

    listen 443; 
    listen [::]:443; 
    include snippets/ssl-example.org.conf; 
    include snippets/ssl-params.conf; 
    server_name notes.example.org; 

    location/{ 
     auth_basic "Restricted Content"; 
     auth_basic_user_file /path/to/passwd/file; 
     include uwsgi_params; 
     uwsgi_pass unix:/path/to/wsgi/socket; 
    } 


} 

請求頭由下WSGI運行應用所看到...

Authorization: Basic **************== 
Content-Length: 0 
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36 
Dnt: 1 
Host: notes.example.org 
Upgrade-Insecure-Requests: 1 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 
Accept-Language: en-US,en;q=0.8 
Content-Type: 
Accept-Encoding: gzip, deflate, sdch, br 
+0

附上您使用nginx的的c​​onf,以便其他人可以回答正確 –

+0

我加入了AUTH配置到原來的職位。 –

回答

1

在這裏,您正在使用HTTP基本身份驗證選項,在nginx服務器給出成功的反饋後,瀏覽器發送username:password的base64。 只是使用Python的base64模塊獲取用戶名密碼&,

>>> from base64 import b64decode 
>>> authorization_header = "dXNlcm5hbWU6cGFzc3dvcmQ=" # value from flask request header 
>>> details = b64decode("dXNlcm5hbWU6cGFzc3dvcmQ=") 
>>> username, password = details.split(':') 
>>> username 
'username' 
>>> password 
'password' 
>>> 
相關問題