【问题标题】:Session cookie not being set on server会话 cookie 未在服务器上设置
【发布时间】:2020-02-07 22:45:12
【问题描述】:

我将 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]

【问题讨论】:

    标签: spring-security-oauth2


    【解决方案1】:

    因此,没有设置会话 cookie 并不完全准确。我想当我在生产中查看它时,我在 chrome 中看错了。但是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。由于是谷歌通过 HTTP 发送它,他们一定认为它是安全的。找不到任何方法让谷歌通过 HTTPS 发送它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-18
      • 2021-11-13
      • 1970-01-01
      • 1970-01-01
      • 2019-06-08
      • 2012-04-14
      • 2018-11-01
      • 2018-08-20
      相关资源
      最近更新 更多