3

I have a flask app that is deployed to azure app services. The app service has SSL certificate that is managed by azure app services. It has also enabled to use only https from TSL/SSL settings in the app services.

I have a couple of absolute redirect url that goes from one page to another. I have set the _scheme=https for these type of absolute url like this

url_for("authorized", _external=True, _scheme = 'https').

I have also set app.config['PREFERRED_URL_SCHEME'] = 'https' and this doesn't seem to work either.

How can I force my flask app absolute url to https in azure app services ? Any suggestions ?

p.s I was following this tutorials https://github.com/AzureAD/microsoft-authentication-library-for-python and it works for the localhost where it doesn't need https. But it fails to create absolute url in https while using in the appservices and because of this, the authentication to AzureAD is not successful.

user96564
  • 1,578
  • 5
  • 24
  • 42

1 Answers1

1

It seems using ProxyFix is a solution for this issues. After using this middleware, I was able to redirect absolute url to https.

app.wsgi_app = ProxyFix(app.wsgi_app)
user96564
  • 1,578
  • 5
  • 24
  • 42
  • 1
    Can you explain what this does? Seems a bit opaque and not sure what other effects this will have on my code? – Zaffer Jan 13 '22 at 21:59
  • 1
    @Zaffer its available here. https://werkzeug.palletsprojects.com/en/2.0.x/middleware/proxy_fix/ – user96564 Jan 14 '22 at 10:22