title: Using Flask-Login to Authenticate Nginx Reverse Proxy
body: <p>I am implementing a modified version of Duo Labs' <a href="https://github.com/duo-labs/py_webauthn" rel="nofollow noreferrer">py_webauthn</a> demo in order to add physical authentication to my website. The demo is built in Flask, and uses the <code>flask-login</code> library in conjunction with an SQLAlchemy database to store user data.</p>
  
  <p>What I would ideally like is for the Flask app to act as an Nginx authenticator, such that a logged-in user is able to access other <code>proxy_pass</code>'ed services on the server.</p>
  
  <p>I had originally attempted to implement the reverse proxies in Flask, but the only working solution I have found requires the Twisted framework (as services like Shellinabox require constant requests being made), which needs a entirely separate WSGI application to be set up—an unnecessary middleman that is difficult to integrate.</p>
  
  <p>My ideal result would be for a user to initially access the server and be <code>proxy-pass</code>'ed to the Flask authentication server, then would be able to access several other reverse-proxied services through Nginx. I am still open to a Python reverse proxy, but have found that Nginx best suits my needs.</p>
  
  <p>How should I go about integrating Flask and Nginx?</p>
  
  <p>(The app.py file for the demo library is available <a href="https://github.com/duo-labs/py_webauthn/blob/master/flask_demo/app.py" rel="nofollow noreferrer">here</a>. The Webauthn functionality is simply built on top of <code>flask-login</code>.)</p>