【问题标题】:Spring boot application with Azure AD throws Reply URL does not match带有 Azure AD 的 Spring Boot 应用程序抛出回复 URL 不匹配
【发布时间】:2023-04-10 19:30:01
【问题描述】:

我有一个与 Azure AD SAML 登录集成的 Spring Boot 应用程序。我遵循this 示例来实现这一点。它在 localhost 中运行良好,但在部署到 prod url 时,它不断给出以下错误

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

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

我还尝试使用堆栈溢出帖子here 中提到的“azure.activedirectory.redirect-uri-template”在 azure 门户和 application.properties 上设置 https URL,但这也不起作用。

我也浏览过this 的帖子,但这也没有帮助。

任何帮助将不胜感激。

【问题讨论】:

  • 您好,请在issue 之后检查您的 Tomcat 服务器。另一种方法是在applications.properties中添加server.forward-headers-strategy=native,避免以http开头。
  • @PamelaPeng,感谢您的回复。添加 server.forward-headers-strategy=native 没有帮助。我还在 application.properties 从您共享的链接中添加了其他行 azure.activedirectory.redirect-uri-template= xxx.xxx.xxx/login/oauth2/code/azuresecurity.oauth2.client.pre-established-redirecturi=xxx.xxx.xxx/login/oauth2/code/azuresecurity.oauth2.client.registered- redirecturi=xxx.xxx.xxx/login/oauth2/code/azuresecurity.oauth2.client.use-current-uri=false server.forward-headers-strategy=native
  • 感谢@PamelaPeng,添加您分享的链接中的所有行解决了问题

标签: spring-boot azure-active-directory saml


【解决方案1】:

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

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

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。答案是here。有关此设置的更多信息,请参阅here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-08
    • 2019-09-16
    • 2017-04-12
    相关资源
    最近更新 更多