If you are using Oauth login/register on a Flask server and its is behind Traefik. You will need to do two things to fix the https and redirect issues. You may be getting errors indicating that the OAuth callback is not valid or is not https enabled. And the intersting part to note is that it will work fine when running on local host and straight up https, but fail when the app is behing a proxy/edege router/traffic multiplexer like Traefik or NGinx.
- Do the Proxy fix to the wsgi app inside of the flask app. This is from the flask documentation itself https://flask.palletsprojects.com/en/1.1.x/deploying/wsgi-standalone/#deploying-proxy-setups
# assuming app is the Flask app
from werkzeug.middleware.proxy_fix import ProxyFix
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1)
- Add the PREFERRED_URL_SCHEME in Flask config to https
class FlaskConfig:
SECRET_KEY = "..." # <<< Standard stuff
SQLALCHEMY_DATABASE_URI = os.getenv("DATABASE_URL")
SQLALCHEMY_TRACK_MODIFICATIONS = False
PREFERRED_URL_SCHEME = "https" # <<< Note here
this is shamelessly copied in parts from https://flask-dance.readthedocs.io/en/latest/proxies.html