Skip to content

7.1.0: Breaking change ServletOAuth2AuthorizedClientExchangeFilterFunction#authorizeClient for @Async methods #19405

Description

@Bego-jon28

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Create a WebClient with ServletOAuth2AuthorizedClientExchangeFilterFunction

public WebClient webClient(WebClient.Builder webClientBuilder, OAuth2AuthorizedClientManager authorizedClientManager) {
    ServletOAuth2AuthorizedClientExchangeFilterFunction oauth2Client = new ServletOAuth2AuthorizedClientExchangeFilterFunction(authorizedClientManager);
    oauth2Client.setDefaultClientRegistrationId("default-oauth");
    return webClientBuilder.apply(oauth2Client.oauth2Configuration()).build();
  }

Later if you execute a request the reauthorizeClient is called but stepped out now earlier due

		if (servletRequest == null || servletResponse == null) {
			return Mono.empty();
		}

we use a method annotated mit @Async.

  
    @Async
    public CompletableFuture<EchoResult> getBearer()  {
        var uriComponents = UriComponentsBuilder.newInstance()
                .scheme("https")
                .host("echo.free.beeceptor.com")
                .build();

        EchoResult body;

        try {
            body = webClient.get()
                    .uri(uriComponents.toUri())
                    .retrieve()
                    .bodyToMono(EchoResult.class)
                    .block();
        } catch (RuntimeException ex) {
             throw new IllegalArgumentException(ex);
        }

        return CompletableFuture.completedFuture(body);
    }

If we use without @Asyncthe authorization works

Expected behavior
Authorization works without servletRequest and servletResponse because addToAttributes handle the nullify values.

Links

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions