【问题标题】:Spring Gateway OAuth - Full URL on redirectSpring Gateway OAuth - 重定向的完整 URL
【发布时间】:2020-11-24 03:30:53
【问题描述】:

我们正在使用 Spring Gateway Service for Security (OAuth2)。登录重定向响应为相对路径 例如:位置:/oauth2/authorization/client1。

我们如何强制在重定向时响应完整的 url(总是,不仅仅是登录)

例如:位置:https://example.com/oauth2/authorization/google

请帮忙。

【问题讨论】:

  • 可以分享配置吗?

标签: spring-boot spring-webflux spring-cloud-gateway


【解决方案1】:

这是我的工作方式 - 至少对于身份验证条目和身份验证成功 url。

  1. 通过扩展 DefaultServerRedirectStrategy 创建一个类,并通过将 baseUrl(模式、主机和端口)添加到 uri 参数来实现 sendRedirect 方法。

  2. 创建一个 RedirectServerAuthenicationSuccessHandler 实例并设置在步骤 1 中创建的 redirectStrategy。

  3. 在 ServerHttpSecurity.oauth2Login() 中设置步骤 2 中创建的 authentionSuccessHandler

  4. 像第 2 步和第 3 步一样,创建一个 RedirectServerAuthenticationEntryPoint 实例,设置 redirectStragey 并将其添加到 ServerHttpSecurity.exceptionHandling()

希望这对寻求解决方案的人有所帮助。

【讨论】:

  • 任何其他解决方案,请发布。
猜你喜欢
  • 2021-04-19
  • 2016-08-21
  • 2022-11-16
  • 1970-01-01
  • 1970-01-01
  • 2015-08-28
  • 2021-11-29
  • 2021-05-19
  • 2017-05-11
相关资源
最近更新 更多