@Override
    public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
            throws IOException {
        if (!request.getHeaders().containsKey(HttpHeaders.AUTHORIZATION)) {
            OAuth2AuthorizedClient authorizedClient = this.authorizedClientManager.authorize(
                    OAuth2AuthorizeRequest.withClientRegistrationId(this.registrationId)
                            .principal(this.securityContextHolderStrategy.getContext().getAuthentication())
                            .build());
            request.getHeaders().setBearerAuth(authorizedClient.getAccessToken().getTokenValue());
        }

        return execution.execute(request, body);
    }
@Test
    void intercept_AuthorizationHeaderIsNotSet_AddsAuthorizationHeader() throws IOException {
        // given
        var request = new MockClientHttpRequest();
        var body = new byte[0];
        var execution = mock(ClientHttpRequestExecution.class);
        var response = new MockClientHttpResponse();
        var authentication = new TestingAuthenticationToken("j.dewar", "password");
        SecurityContextHolder.getContext().setAuthentication(authentication);

        var authorizedClient = new OAuth2AuthorizedClient(mock(), "j.dewar",
                new OAuth2AccessToken(OAuth2AccessToken.TokenType.BEARER, "token", Instant.now(), Instant.MAX));
        doReturn(authorizedClient).when(this.authorizedClientManager)
                .authorize(argThat(authorizationRequest ->
                        authorizationRequest.getPrincipal().equals(authentication) &&
                                authorizationRequest.getClientRegistrationId().equals("test")));

        doReturn(response).when(execution).execute(request, body);

        // when
        var result = this.interceptor.intercept(request, body, execution);

        // then
        assertEquals(response, result);
        assertEquals("Bearer token", request.getHeaders().getFirst(HttpHeaders.AUTHORIZATION));

        verify(execution).execute(request, body);
        verifyNoMoreInteractions(execution);
    }