我正在使用Spring堆栈(Spring Boot 2.0.1.RELEASE)创建一个站点,该站点通过OAuth2将用户身份验证/注册委托给Facebook。当我单击“使用Facebook登录”按钮时,我被重定向到Facebook,但是Spring Security OAuth2正在使用http而不是https创建redirect_uri参数。该应用程序使用https,但我不知道此“ http”的来源。
那么,如何使Spring正确创建redirect_uri参数?
更新
抱歉,原来的帖子。已经很晚了,我想在睡觉前发布问题:-)
好吧,我的应用程序使用了Spring Security 2.0.1.RELEASE和Spring Security OAuth2 5.0.4.RELEASE附带的Spring Boot 2.0.1.RELEASE。我的应用程序使用Facebook来注册和验证用户。目前,我有一个在AWS(Beanstalk)中运行并使用Amazon的SSL证书的测试环境。
当我第一次写帖子时,我的问题是我的应用程序(实际上是通过SS)发送给Facebook的redirect_uri参数具有一个HTTP前缀,而不是https。这在Facebook中导致错误,该错误仅接受https重定向URL。
阅读文档后,我发现了该spring.security.oauth2.client.registration.facebook.redirect-uri-template属性,并将其设置为https://[my domain]/login/oauth2/code/{registrationId}。现在,Facebook处理我的身份验证请求并将其发布回我的应用程序。
但是,使用先前的参数集,现在问题已改变。现在,当Facebook的回调在AWS上击中我的应用程序时,我将收到以下异常(来自日志):
2018-04-11 10:51:23 [http-nio-5000-exec-5] DEBUG o.s.s.o.c.w.OAuth2LoginAuthenticationFilter - Request is to process authentication
2018-04-11 10:51:23 [http-nio-5000-exec-5] DEBUG o.s.s.authentication.ProviderManager - Authentication attempt using org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationProvider
2018-04-11 10:51:23 [http-nio-5000-exec-5] DEBUG o.s.s.authentication.ProviderManager - Authentication attempt using org.springframework.security.oauth2.client.oidc.authentication.OidcAuthorizationCodeAuthenticationProvider
2018-04-11 10:51:23 [http-nio-5000-exec-5] DEBUG o.s.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.authentication.OAuth2LoginAuthenticationProvider.authenticate(OAuth2LoginAuthenticationProvider.java:117)
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:174)
at org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter.attemptAuthentication(OAuth2LoginAuthenticationFilter.java:159)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:212)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at …Run Code Online (Sandbox Code Playgroud)