未在服务器上设置会话Cookie

时间:2019-10-10 13:11:50

标签: spring-security-oauth2

我将OAuth2登录表单前端更改为后端实现。 OAuth2Login使用Spring安全性配置进行设置。 一切都在本地计算机上工作。

但是在服务器上,它不再创建会话Cookie。我猜这会产生以下异常:

org.springframework.security.oauth2.core.OAuth2AuthenticationException: [authorization_request_not_found] 
        at org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter.attemptAuthentication(OAuth2LoginAuthenticationFilter.java:165) ~[spring-security-oauth2-client-5.1.2.RELEASE.jar!/:5.1.2.RELEASE]

1 个答案:

答案 0 :(得分:0)

因此,未设置会话cookie并不完全准确。我认为在生产过程中在镀铬中看错了。但是Cookie似乎已重置。

spring:
  security:
    oauth2:
      client:
        registration:
          google:
            redirectUri: https://<youurl>/login/oauth2/code/google

当我添加此内容时,它会产生新的问题:

org.springframework.security.oauth2.core.OAuth2AuthenticationException: [invalid_redirect_uri_parameter] 
        at org.springframework.security.oauth2.client.oidc.authentication.OidcAuthorizationCodeAuthenticationProvider.authenticate(OidcAuthorizationCodeAuthenticationProvider.java:132) ~[spring-security-oauth2-client-5.1.2.RELEASE.jar!/:5
.1.2.RELEASE]
        at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:175) ~[spring-security-core-5.1.6.RELEASE.jar!/:5.1.6.RELEASE]
        at org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter.attemptAuthentication(OAuth2LoginAuthenticationFilter.java:186)

这是因为redirectUri是HTTPS,但是Google始终返回HTTP 因此,我最后添加了一个阅读Stack Overflow post的内容,并为我的项目添加了OncePerRequestFilter。由于是Google通过HTTP发送此消息,因此他们必须认为它是安全的。无法找到使Google通过HTTPS发送的任何方法

相关问题