Spring 使用 Azure AD 启动应用程序抛出回复 URL 不匹配

Spring boot application with Azure AD throws Reply URL does not match

我有一个 spring 启动应用程序与 Azure AD SAML 登录集成。我已按照 this 示例来实现此目的。它在本地主机上运行良好,但在部署到产品 url 时,它一直给出以下错误

我在授权请求中看到的重定向 uri URL 以 http 开头。这是矛盾的,因为 Azure 应用程序注册不允许配置任何非 https URLs,唯一的例外是 localhost。

为了匹配 URLs,我尝试在 Azure 门户中编辑 App Registration 的清单以使其成为 http。现在,似乎 URLs 匹配,但随后出现以下错误:

我还尝试在 Azure 门户和 application.properties 上使用堆栈溢出中提到的“azure.activedirectory.redirect-uri-template”设置 https URL post 但这也行不通。

我也经历了 this post 但这也没有帮助。

如有任何帮助,我们将不胜感激。

为了解决重定向到https但请求中的redirect_uri仍然以http开头的错误,有两个类似的问题:

1. HTTPS 请求在代理处终止,然后代理使用 HTTP 协议与您的 Tomcat 服务器通信。如果您将代码部署在 App Service 等云提供商上,您将面临这种情况。答案是 .

application.properties:

security.oauth2.client.pre-established-redirect-uri=https://yourappurl.net/login
security.oauth2.client.registered-redirect-uri=https://yourappurl.net/login
security.oauth2.client.use-current-uri=false
server.tomcat.remote-ip-header=x-forwarded-for
server.tomcat.protocol-header=x-forwarded-proto
server.tomcat.use-relative-redirects=true
server.use-forward-headers=true
server.tomcat.internal-proxies=.*

2.在applications.properties中添加server.forward-headers-strategy=native。答案是. For more about this setting, see .