1

I have a flask app (using Python version 3.7) running on an Apache server (version 2.4), using mod_wsgi (version 4.6.4), and SQLAlchemy (1.2.11).

I am working on designing a logic where I want to get the name of the manager of the current user logged in on Windows:

(Using get pass module with getuser method).

My query:

get_manager_name = session.query(Table.employee_first_name + " " + Table.employee_last_name).filter(Table.employee_net_username == getpass.getuser()).all()

The above query works if I bypass Apache (using the development server that comes with Flask).

On the other hand, If I use Apache, then the query returns an empty list [].

I debugged my code using logging module in Python (logging.debug(getpass.getuser())) and found that getpass.getuser() returns the name of the service account under which Apache is running on my end and not the username of the current user logged in.

So my question is what I need to do to get the username of the logged in user through Apache on Windows?

I found a similar question on the similar issue, but it was related to IIS:

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

jww
  • 97,681
  • 90
  • 411
  • 885
LinuxUser
  • 635
  • 1
  • 7
  • 19
  • Possible duplicate of [How to make Python get the username in windows and then implement it in a script](https://stackoverflow.com/questions/13654122/how-to-make-python-get-the-username-in-windows-and-then-implement-it-in-a-script) – Fine Sep 17 '18 at 16:33
  • Does not work. It gives the username of the service account under which Apache is running. I have even tried os.environ['USERNAME'] It prints the username of the logged in user if I bypass Apache. Under apache, it prints the service account under which Apache is running. – LinuxUser Sep 17 '18 at 16:54
  • 1
    I _think_ you'll need Kerberos authentication for this and some kind of security configuration on the browser. – msg Sep 17 '18 at 19:08
  • Did you try `request.environ['REMOTE_USER']` ? – godimedia Oct 01 '18 at 19:07

1 Answers1

0

There was a need to set up a middleware so that the logged in user's username can be sent to Flask app from Apache.

Was able to resolve by following:

http://flask.pocoo.org/snippets/69/

LinuxUser
  • 635
  • 1
  • 7
  • 19