Spring boot cloud gateway and keycloak 401 error

Hi All

Hopefully someone will be able to point me in the right direction. I am working on a spring boot microservices project using keycloak to authenticate users.

The spring boot service gateway is able to interact with keycloak and login to the application. After a period of inactivity. The gateway returns a HTTP 401 response to the client, is it possible to redirect the user back to the keycloak login page when this happens.

The Security Configuration for the service gateway is as follows.

@Configuration
@EnableWebFluxSecurity
public class SecurityConfig {

@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
    
    http                   
            .authorizeExchange(exchanges -> exchanges                
                    .anyExchange().authenticated())
            .oauth2Login(withDefaults()).exceptionHandling();
    http.csrf().disable();
    return http.build();
}

}