spring-security icon indicating copy to clipboard operation
spring-security copied to clipboard

removeAuthorizationRequest of HttpSessionOAuth2AuthorizationRequestRepository always return null

Open Y-k-Y opened this issue 2 years ago • 3 comments

Describe the bug removeAuthorizationRequest method of HttpSessionOAuth2AuthorizationRequestRepository always return null which cause OAuth2AuthenticationException when using it with GenericJackson2JsonRedisSerializer

To Reproduce

  1. Configure project included below dependencies
plugins {
    id 'java'
    id 'org.springframework.boot' version '2.7.8'
    id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

sourceCompatibility = '11'

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-data-redis'
    implementation('org.springframework.session:spring-session-data-redis') {
        exclude group: 'org.springframework.data', module: 'spring-data-redis'
    }
}
  1. Configure redis to use Generic2Jackson2JsonRedisSerializer so that session value can be stored as json format
  2. Try to authenticate through oauth2 protocol

Expected behavior It should be return appropriate request value no matter what format we use.

Sample Look around this Sample and don't forget to configure oauth2 properties with yours

Y-k-Y avatar Feb 10 '23 01:02 Y-k-Y

@Y-k-Y Hello, have you been able to solve this problem? I have a very similar problem, but with Spring Boot 3.

ilyako87 avatar Jul 07 '23 09:07 ilyako87

@ilyako87 Unfortunately i couldn't solve this problem. I had to use the default serializer. If you encounter similar issue with mine then i guess it didn't fixed yet. Let me know if you solve your problem i also want to know how to solve this one as well.

Y-k-Y avatar Jul 10 '23 14:07 Y-k-Y

I came across a similar issue today but it's nothing to do with serializer. I was debugging the application on a remote server with https disable. However the cookie was configured to be secure, thus not sent to the server, then it kept creating new sessions.

wylswz avatar Feb 01 '24 10:02 wylswz

Thanks for reaching out @Y-k-Y! Apologies that this issue was not responded to for a long time.

Thank you for providing a sample. It appears that you are not configuring the ObjectMapper for Redis per the documentation. I believe it would look like this (which works when I change your sample). I don't think you need the RedisTemplate @Bean in your sample to make Spring Session work.

sjohnr avatar Jun 05 '24 20:06 sjohnr

Thank you @sjohnr! Yes i can confirm that it resolves the issue. I should configure ObjectMapper for serializer not RedisTemplate.

Y-k-Y avatar Jun 07 '24 00:06 Y-k-Y