首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在Spring Security oauth2中调试重定向uris?

如何在Spring Security oauth2中调试重定向uris?
EN

Stack Overflow用户
提问于 2019-01-30 18:38:39
回答 1查看 1.3K关注 0票数 1

我正在使用Spring Security在我的Spring Boot web应用程序中设置oauth2身份验证,该应用程序在反向代理之后运行。

流程:

1)导航到我的Spring应用程序的登录页面

2)重定向到oauth提供者。正在登录。

3)重定向回我的redirect-uri端点

4)流程中断和默认Spring登录页面打印:

代码语言:javascript
运行
复制
Your login attempt was not successful, try again.

Reason: [invalid_redirect_uri_parameter]

我打开调试,控制台显示:

代码语言:javascript
运行
复制
2019-01-30 09:46:40.094 DEBUG 1 --- [nio-8080-exec-2] o.s.s.authentication.ProviderManager     : Authentication attempt using org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationProvider
2019-01-30 09:46:40.094 DEBUG 1 --- [nio-8080-exec-2] o.s.s.authentication.ProviderManager     : Authentication attempt using org.springframework.security.oauth2.client.oidc.authentication.OidcAuthorizationCodeAuthenticationProvider
2019-01-30 09:46:40.095 DEBUG 1 --- [nio-8080-exec-2] .s.o.c.w.OAuth2LoginAuthenticationFilter : Authentication request failed: org.springframework.security.oauth2.core.OAuth2AuthenticationException: [invalid_redirect_uri_parameter] 
org.springframework.security.oauth2.core.OAuth2AuthenticationException: [invalid_redirect_uri_parameter] 
    at org.springframework.security.oauth2.client.oidc.authentication.OidcAuthorizationCodeAuthenticationProvider.authenticate(OidcAuthorizationCodeAuthenticationProvider.java:136) ~[spring-security-oauth2-client-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]

深入研究OidcAuthorizationCodeAuthenticationProvider.java的代码会发现以下语句触发了错误:(authorizationResponse.getRedirectUri().equals(authorizationRequest.getRedirectUri()))

我检查了浏览器请求。我的初始请求的重定向uri参数等于我在提供商的站点进行身份验证后被重定向的站点。(否则提供程序将抛出重定向uri不匹配错误)。

根据另一个用户的经验(http://blog.davidvassallo.me/2018/08/10/lessons-learnt-of-spring-boot-oauth2-redirect-uris/),Spring Boot在反向代理后面运行时会看到' localhost‘,因此redirect-uri不再相等(当localhost不是正确的主机名时)。

如何获取authorizationResponse.getRedirectUri()authorizationRequest.getRedirectUri()的值?我想看看Spring Security看到的是哪个重定向uri。调试控制台不会打印这些值。

EN

回答 1

Stack Overflow用户

发布于 2019-09-25 23:18:51

我创建了一个输出request.getRequestURL().toString()的端点,实际上它打印的是原始url,而不是反向代理url。这可能就是问题所在。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54438597

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档