sjohnr / spring-authorization-server

A community-driven project led by the Spring Security team and is focused on delivering Authorization Server support to the Spring community

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalid when WebClient or RestTemplate is set to lb in jwtDecoder

zxuanhong opened this issue · comments

Describe the bug

webflux

  1. Invalid when webClient is set to lb in jwtDecoder
  2. code
 @Bean
    @LoadBalanced
    public WebClient.Builder webClientBuilder() {
        return WebClient.builder();
    }
http.oauth2ResourceServer((resourceServer) -> resourceServer
                    // 使用jwt
                    .jwt(jwtSpec -> jwtSpec
                            // 设置jwt解析器适配器
                            .jwtAuthenticationConverter(grantedAuthoritiesExtractor())
                            .jwtDecoder(
                                    NimbusReactiveJwtDecoder
                                            .withIssuerLocation(properties.getJwt().getIssuerUri())
                                            .webClient(builder.build())
                                            .build()
                            )
                    )
            );

webMvc

 @Bean
    @LoadBalanced
    public RestTemplate loadBalanced() {
        return new RestTemplate();
    }

http.oauth2ResourceServer((resourceServer) -> resourceServer
                    // 使用jwt
                    .jwt(jwtSpec -> jwtSpec
                            // 设置jwt解析器适配器
                            .jwtAuthenticationConverter(jwtAuthenticationConverter())
                            .decoder(
                                    NimbusJwtDecoder
                                            .withIssuerLocation(properties.getJwt().getIssuerUri())
                                            .restOperations(restTemplate())
                                            .build()
                            )
                    )
            );

To Reproduce
Steps to reproduce the behavior.

webflux

  1. The authorization service is started first, and then the gateway is started
image
  1. The authorization service is stopped based on the above, and an exception is called. Restart the authorization service. You keep getting an error no matter how you call it
image

webmvc

  1. webmvc can't parse directly, no matter how you operate it.And start to report an error, can not start directly
image