title: How to get the username of the current user logged in a Flask app running on an Apache server?
body: <p>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).</p>
  
  <p>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:</p>
  
  <p>(Using get pass module with getuser method).</p>
  
  <p>My query:</p>
  
  <pre><code>get_manager_name = session.query(Table.employee_first_name + " " + Table.employee_last_name).filter(Table.employee_net_username == getpass.getuser()).all()
  </code></pre>
  
  <p>The above query works if I bypass Apache (using the development server that comes with Flask).</p>
  
  <p>On the other hand, If I use Apache, then the query returns an empty list <code>[]</code>.</p>
  
  <p>I debugged my code using logging module in Python <code>(logging.debug(getpass.getuser()))</code> and found that <code>getpass.getuser()</code> 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.</p>
  
  <p>So my question is what I need to do to get the username of the logged in user through Apache on Windows?</p>
  
  <p>I found a similar question on the similar issue, but it was related to IIS:</p>
  
  <p><a href="https://stackoverflow.com/questions/39627947/how-do-i-get-the-username-of-the-current-user-in-a-flask-app-on-an-iis-server-us">How do I get the username of the current user in a Flask app on an IIS server using Windows Authentication?</a></p>