Azure-Samples / ms-identity-python-webapp

A Python web application calling Microsoft graph that is secured using the Microsoft identity platform
MIT License
279 stars 133 forks source link

flask.redirect does not work as expected behind reverse proxy #109

Closed nicodravis closed 1 year ago

nicodravis commented 1 year ago

Hello folks,

I have the following setup - serving with Waitress (http) behind an IIS reverse proxy for SSL/TLS support. Once I enabled the reverse proxy, the redirect function started appending all redirects to the proxied URL. The proxied URL is the VM host name (servername) at default ports 80/443, channeling requests to another port.

The issue is that when using the redirect function, instead of getting a redirect for (https://login.microsoftonline.com)/tenant.. I am getting a "proxied redirect" for my proxied URL - servername/tenant.., and this is happening for all redirects. If I put a redirect('www.github.com'), it redirects to servername/www.github.com.

Any thoughts here how I can overcome this?

Best, Nico

rayluo commented 1 year ago

If I put a redirect('www.github.com'), it redirects to servername/www.github.com.

This is clearly outside of the scope of this sample which specializes in authentication.

You shall create a new issue in Flask repo, asking that redirect('www.github.com') question only. Do not mention anything about "login.microsoftonline.com", as it would be a red-herring for your case.

nicodravis commented 1 year ago

Hi Ray, Thanks for your response, I am taking a note on that. While I wanted to illustrate the behaviour change once the reverse proxy was enabled, I realize the examples I provided might have been misleading. As you're tackling the reverse proxy scenario using redirects, I presumed I could ask where I might be getting things wrong with the sample as instead of getting a proper logout redirect URL, I started receiving the proxied URL instead of the AUTHORITY one followed by the tenant id and remaining URL parts.

Thanks for your comments.

rayluo commented 1 year ago

I mean, based on what you described, you could probably reproduce the issue with only these lines plus this:

@app.route("/")
def index():
    return redirect("the content you chose")

At that point it would be a Flask usage question, wouldn't it?