0

I changed OAuth2 Login form frontend to backend implementation. OAuth2Login is setup using spring security configuration. Everything worked in local machine.

But on server it doesn't create Session Cookie anymore. Which, I guess, creates the following exception:

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]

Mihkel L.
  • 1,543
  • 1
  • 27
  • 42

1 Answers1

0

So it wasn't entirely accurate that the session cookie wasn't being set. I think I looked it wrongly in chrome when I was looking it in production. But the cookie was seemed to be reset.

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

When I added this it created new problem:

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)

This is because redirectUri is HTTPS but google always returns HTTP So I ended up adding reading a Stack Overflow post and added a OncePerRequestFilter to my project. Since it's google that is sending this over HTTP they must be thinking it's secure. Couldn't find any way to make google send it over HTTPS

Mihkel L.
  • 1,543
  • 1
  • 27
  • 42