Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable autologin into flask app using active directory

I have made flask web app meant to be used within my organisation.

My problem is currently the login works by requesting a username and password from the user which are then authenticated by an LDAP server.

I would like to be able to autologin a user immediately he gets onto the site since that's how other company internal websites work(these others were made in C# and php)

My main problem is:

  • Is there a python package to get the client's windows username immediately he gets on to the site? and how would I use it

Requests-ntlm was once suggested but it has no documentation.

I have tried to look at several stack overflow questions but they do not address my problem eg link

like image 535
machazthegamer Avatar asked Oct 20 '17 13:10

machazthegamer


People also ask

How do you use a JWT in Flask?

To install it, type sudo apt install python3-venv in your terminal and then you are good to go. If you are on windows then use something like virtualenv to make a virtual environment. This will create a folder named venv in the flask project which will contain the project specific libraries.


1 Answers

It has taken me weeks to find the answer but Yes it is possible but you must configure the server where your app is hosted to allow this. In my case I was using IIS and enabled windows authentication. With this its surprisingly easy to get the active directory user name as it comes as part of the HTTP response:

from flask import request
username = request.environ.get('REMOTE_USER')

See this question for more information:

How to access Apache Basic Authentication user in Flask

like image 85
machazthegamer Avatar answered Sep 21 '22 13:09

machazthegamer