Azure-Samples / ms-identity-python-webapp

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

Https access to webpage with MS identity #71

Closed JetDanTe closed 1 year ago

JetDanTe commented 2 years ago

Hello. I try to create a web page with MS auth. At localhost it work properly with https://127.0.0.1:5000 or http://127.0.0.1:5000. (Both of these links provided in Azure in redirect field) If i want to start it on external server using Apache2 it can not auth. I think it fails bacause the redirect_url in MS login page does not have httpS. It is look like http://myapp.com/getAToken but in Azure I can add only httpS links.

rayluo commented 2 years ago

in Azure I can add only httpS links

That is indeed the case here. Azure Portal does not allow you to setup an app redirect_uri without httpS, for security reason.

From an architecture standpoint, that requirement is implemented in and enforced by Azure Portal, not by this MSAL-powered web app sample here. So, should you have any follow-up questions on this topic, you may try use the Feedback form in Azure Portal.

judiaz commented 2 years ago

You can "bypass" this if you manually edit the auth_uri and redirect_uri whit something like this redirect_uri=redirect_uri.replace('https://localhost','http://localhost'))

rayluo commented 2 years ago

There seems to be some confusion on this topic.

The last time I tried it, Azure Portal allows you to set redirect_uri as http://localhost or httpS://contoso.com/some/path, both would also accept an optional port. In other words, the non-httpS url is only allowed for localhost. In all cases, this web sample would work as long as the settings in your app_config.py matches your app's registration in Azure Portal. You should not need any extra manual code to change the redirect_uri value on-the-fly.