Source:
public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { String clientRegistrationId = this.resolveClientRegistrationId(parameter); if (StringUtils.isEmpty(clientRegistrationId)) { throw new IllegalArgumentException("Unable to resolve the Client Registration Identifier. " + "It must be provided via @RegisteredOAuth2AuthorizedClient(\"client1\") or " + "@RegisteredOAuth2AuthorizedClient(registrationId = \"client1\")."); } ClientRegistration clientRegistration = this.clientRegistrationRepository.findByRegistrationId(clientRegistrationId); if (clientRegistration == null) { return null; } Authentication principal = SecurityContextHolder.getContext().getAuthentication(); HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class); OAuth2AuthorizedClient authorizedClient = this.authorizedClientRepository.loadAuthorizedClient( clientRegistrationId, principal, servletRequest); if (authorizedClient != null) { if (AuthorizationGrantType.AUTHORIZATION_CODE.equals(clientRegistration.getAuthorizationGrantType())) { } if (AuthorizationGrantType.CLIENT_CREDENTIALS.equals(clientRegistration.getAuthorizationGrantType())) { if (hasTokenExpired(authorizedClient)) { HttpServletResponse servletResponse = webRequest.getNativeResponse(HttpServletResponse.class); authorizedClient = this.authorizeClientCredentialsClient(clientRegistration, servletRequest, servletResponse); } } return authorizedClient; } if (AuthorizationGrantType.AUTHORIZATION_CODE.equals(clientRegistration.getAuthorizationGrantType())) { throw new ClientAuthorizationRequiredException(clientRegistrationId); } if (AuthorizationGrantType.CLIENT_CREDENTIALS.equals(clientRegistration.getAuthorizationGrantType())) { HttpServletResponse servletResponse = webRequest.getNativeResponse(HttpServletResponse.class); authorizedClient = this.authorizeClientCredentialsClient(clientRegistration, servletRequest, servletResponse); } return authorizedClient; }

Target:
public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { String clientRegistrationId = this.resolveClientRegistrationId(parameter); if (StringUtils.isEmpty(clientRegistrationId)) { throw new IllegalArgumentException("Unable to resolve the Client Registration Identifier. " + "It must be provided via @RegisteredOAuth2AuthorizedClient(\"client1\") or " + "@RegisteredOAuth2AuthorizedClient(registrationId = \"client1\")."); } ClientRegistration clientRegistration = this.clientRegistrationRepository.findByRegistrationId(clientRegistrationId); if (clientRegistration == null) { return null; } Authentication principal = SecurityContextHolder.getContext().getAuthentication(); HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class); OAuth2AuthorizedClient authorizedClient = this.authorizedClientRepository.loadAuthorizedClient( clientRegistrationId, principal, servletRequest); if (authorizedClient != null) { return authorizedClient; } if (AuthorizationGrantType.AUTHORIZATION_CODE.equals(clientRegistration.getAuthorizationGrantType())) { throw new ClientAuthorizationRequiredException(clientRegistrationId); } if (AuthorizationGrantType.CLIENT_CREDENTIALS.equals(clientRegistration.getAuthorizationGrantType())) { HttpServletResponse servletResponse = webRequest.getNativeResponse(HttpServletResponse.class); authorizedClient = this.authorizeClientCredentialsClient(clientRegistration, servletRequest, servletResponse); } return authorizedClient; }