Source:
public Mono<Object> resolveArgument( MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange) { return Mono.defer(() -> { RegisteredOAuth2AuthorizedClient authorizedClientAnnotation = AnnotatedElementUtils .findMergedAnnotation(parameter.getParameter(), RegisteredOAuth2AuthorizedClient.class); Mono<String> clientRegistrationId = Mono.justOrEmpty(authorizedClientAnnotation.registrationId()) .filter(id -> !StringUtils.isEmpty(id)) .switchIfEmpty(clientRegistrationId()) .switchIfEmpty(Mono.defer(() -> Mono.error(new IllegalArgumentException( "Unable to resolve the Client Registration Identifier. It must be provided via @RegisteredOAuth2AuthorizedClient(\"client1\") or @RegisteredOAuth2AuthorizedClient(registrationId = \"client1\").")))); Mono<String> principalName = ReactiveSecurityContextHolder.getContext() .map(SecurityContext::getAuthentication).map(Authentication::getName); Mono<OAuth2AuthorizedClient> authorizedClient = Mono .zip(clientRegistrationId, principalName).switchIfEmpty( clientRegistrationId.flatMap(id -> Mono.error(new IllegalStateException( "Unable to resolve the Authorized Client with registration identifier \"" + id + "\". An \"authenticated\" or \"anonymous\" request is required. To allow for anonymous access, ensure ServerHttpSecurity.anonymous() is configured.")))) .flatMap(zipped -> { String registrationId = zipped.getT1(); String username = zipped.getT2(); return this.authorizedClientService .loadAuthorizedClient(registrationId, username).switchIfEmpty(Mono.defer(() -> Mono .error(new ClientAuthorizationRequiredException( registrationId)))); }).cast(OAuth2AuthorizedClient.class); return authorizedClient.cast(Object.class); }); }

Target:
public Mono<Object> resolveArgument( MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange) { return Mono.defer(() -> { RegisteredOAuth2AuthorizedClient authorizedClientAnnotation = AnnotatedElementUtils .findMergedAnnotation(parameter.getParameter(), RegisteredOAuth2AuthorizedClient.class); Mono<String> clientRegistrationId = Mono.justOrEmpty(authorizedClientAnnotation.registrationId()) .filter(id -> !StringUtils.isEmpty(id)) .switchIfEmpty(clientRegistrationId()) .switchIfEmpty(Mono.defer(() -> Mono.error(new IllegalArgumentException( "Unable to resolve the Client Registration Identifier. It must be provided via @RegisteredOAuth2AuthorizedClient(\"client1\") or @RegisteredOAuth2AuthorizedClient(registrationId = \"client1\").")))); Mono<String> principalName = ReactiveSecurityContextHolder.getContext() .map(SecurityContext::getAuthentication).map(Authentication::getName); Mono<OAuth2AuthorizedClient> authorizedClient = Mono .zip(clientRegistrationId, principalName).switchIfEmpty( clientRegistrationId.flatMap(id -> Mono.error(new IllegalStateException( "Unable to resolve the Authorized Client with registration identifier \"" + id + "\". An \"authenticated\" or \"unauthenticated\" session is required. To allow for unauthenticated access, ensure ServerHttpSecurity.anonymous() is configured.")))) .flatMap(zipped -> { String registrationId = zipped.getT1(); String username = zipped.getT2(); return this.authorizedClientService .loadAuthorizedClient(registrationId, username).switchIfEmpty(Mono.defer(() -> Mono .error(new ClientAuthorizationRequiredException( registrationId)))); }).cast(OAuth2AuthorizedClient.class); return authorizedClient.cast(Object.class); }); }