Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the username of the current user in a Flask app on an IIS server using Windows Authentication?

I have a Flask app (Python 2.7) running on an IIS server in Windows 10. The server is configured to use Windows Authentication. I am using an HttpPlatformHandler in order to execute the Python code.

I have verified that the authentication is working and am able to see the Kerberos "Negotiate" auth header. However, I cannot find a way to access the username of the user who requested the page.

I have tried printing the entire request header and request environment and it is not there. This post seems to be about my issue but the code in it is not correct. What can I do to pass the Windows username of the requester to my python code?

I would like to access the username of the user in order to both restrict page access by user and remove certain elements from pages based on user.

like image 211
scomes Avatar asked Sep 21 '16 23:09

scomes


People also ask

Which of the following can be used to login a user in flask?

Flask-Login can manage user sessions. Start by adding the UserMixin to your User model. The UserMixin will add Flask-Login attributes to the model so that Flask-Login will be able to work with it. With Flask-Login setup, use the /login route.

How do I authenticate my flask app?

For authentication, we'll use the Python library flask_login . This app includes features such as form validations, account creation, and login/logout functionality for authenticated users.

How do I run flask app on Windows server?

Inside FlaskApp folder, create the Flask Application file “app.py”. Now, copy the “wfastcgi.py” file from “C:\Python\Lib\site-packages\” directory and paste it to “C:\inetpub\wwwroot\FlaskApp\” directory. Now, as the permissions are added, we are ready to deploy our Flask application in the IIS server.


1 Answers

It turns out that the answer on this post works for my configuration as well. I simply downloaded ISAPI_Rewrite 3, copy and pasted the text into httpd.conf, and was able to access the name of the user by calling request.headers.get('X-Remote-User') in my Python code.

like image 141
scomes Avatar answered Nov 02 '22 02:11

scomes