Azure App Service web app: Django + Microsoft login redirect HTTPS issue

huangapple go评论69阅读模式
英文:

Azure App Service web app: Django + Microsoft login redirect HTTPS issue

问题

Azure应用注册的Web重定向URL(它是HTTPS),如下所示:

使用Azure应用服务成功部署了Django Web应用程序:

上述部署结果显示http://,但在Azure Web应用程序中显示https://,还可以成功使用有效的https://打开Web应用程序,如下所示:

但是,当Web应用程序重定向到Microsoft站点以进行登录时,它再次使用http://,这与应用程序注册中配置的https://不匹配:

MS身份验证和重定向由ms_identity_web包处理,代码提供自https://github.com/Azure-Samples/ms-identity-python-django-tutorial/tree/main/1-Authentication/sign-in

在开发环境中没有问题,因为我在应用注册中将Web重定向URL设置为http://localhost:8000/auth/redirect。

我的问题可能与这个问题相同:链接,但它涵盖了URL详细信息,因此不确定是否是相同的http/https不匹配问题。

英文:

Azure App registration web redirect URL (it's HTTPS) as below:
Azure App Service web app: Django + Microsoft login redirect HTTPS issue

Using Azure App Service deployed the Django web app successfully:
Azure App Service web app: Django + Microsoft login redirect HTTPS issue

the above deploying result shows http://, but in Azure web app web it shows https://, also could open the web app using https successfully with valid as below:

Azure App Service web app: Django + Microsoft login redirect HTTPS issue

But when the web app redirected to Microsoft site to login, it uses http:// again which doesn't match the https:// configured in App registration:

Azure App Service web app: Django + Microsoft login redirect HTTPS issue

The MS authentication and redirection is handled by package ms_identity_web, code
provided from https://github.com/Azure-Samples/ms-identity-python-django-tutorial/tree/main/1-Authentication/sign-in

In development environment there is no issue since I use http://localhost:8000/auth/redirect as web redirect url in App registration.

My issue could be the same as this one: link, but it covered the URL details so not sure if it was the same http/https mismatching issue.

答案1

得分: 0

已通过将以下内容添加到 settings.py 中解决了此问题:

SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

参考链接:https://github.com/Azure-Samples/ms-identity-python-django-tutorial/issues/5

英文:

Solved the issue by adding the below into settings.py

SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

reference: https://github.com/Azure-Samples/ms-identity-python-django-tutorial/issues/5

huangapple
  • 本文由 发表于 2023年6月29日 12:05:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76577998.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定