My Flask web application requires a Microsoft login feature.
The Microsoft login requires a redirect url that redirects the user back to Flask after successfully login in Microsoft.
My HTTPS structure is: Nginx listening at 443, and proxy all request to http://127.0.0.1:5000, where my Flask app is running. (The most popular method I found for running Flask as production mode using HTTPS )
Now comes the problem: The redirect url sent to Microsoft login, is http://127.0.0.1:5000
But all other redirects, e.g.: (ignore my function names, you know what I mean)
resp = resp.set(url_for('index'),200)
return resp
or
return redirect('/whatever_page')
are all redirected as https://example.com/{whatever_page}, which is completely fine.
But when it comes to the redirect url used in Microsoft login, it failed.
The Microsoft login code I am using is basically the flask demo I downloaded from Microsoft, all I did is simply changed the entire thing into another function of my Flask app, and call it when I need it. I did went through the codes step by step and did everything I could to make things right, yet nothing worked.
I have tried changing the IP in proxy_pass to the public IP and some other IPs, they didn't work but I can see the IP used in redirect url changes with the proxy_pass IP.
I have tried many configurations that might make things right, for examples:
proxy_redirect: http://127.0.0.1:5000/getAToken http://example.com/getAToken
or
proxy_redirect: http://127.0.0.1:5000/ https://example.com/
or
proxy_redirect: http://127.0.0.1:5000/ http://example.com/
or
proxy_redirect: http://127.0.0.1:5000/getAToken https://example.com/getAToken
Exedra
None of the proxy_redirect configurations can affect the redirect url used in Microsoft login, but all other redirects work.
I even tried to change the redirect url manually by modifying the login url Microsoft generated, it didn't work since the redirect_url is used to encrypt the token or whatever it is.
My current hacky options are:
- Running back to developmental using HTTPS, but I need to restart the service every 1h or so to avoid the "not responding" problem in developmental server. Costs are: Lost of cache and potential crash when more users come. (which is what I am currently using to keep the website up)
- Use a window server. Developmental mode on window server doesn't stop responding, it may at some point but I honestly don't know, I do have one running for months and never stop responding. The problem here is I don't know when it will stop responding.
- Buy another server and use it as a login server, it can be restarted every hour since cache or whatever is doesn't matter there.
But I really want to solve this problem without using any options above, and modify the redirect URL before the Microsoft login url is generated is the best option I can think of, I just don't know how to.
If there are other options other than these, please let me know, I will really appreciate it.