Source:
public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { OAuth2Client oauth2ClientAnnotation = parameter.getParameterAnnotation(OAuth2Client.class); Authentication principal = SecurityContextHolder.getContext().getAuthentication(); String clientRegistrationId = null; if (!StringUtils.isEmpty(oauth2ClientAnnotation.registrationId())) { clientRegistrationId = oauth2ClientAnnotation.registrationId(); } else if (!StringUtils.isEmpty(oauth2ClientAnnotation.value())) { clientRegistrationId = oauth2ClientAnnotation.value(); } else if (principal != null && OAuth2AuthenticationToken.class.isAssignableFrom(principal.getClass())) { clientRegistrationId = ((OAuth2AuthenticationToken) principal).getAuthorizedClientRegistrationId(); } if (StringUtils.isEmpty(clientRegistrationId)) { throw new IllegalArgumentException("Unable to resolve the Client Registration Id"); } if (ClientRegistration.class.isAssignableFrom(parameter.getParameterType())) { return this.clientRegistrationRepository.findByRegistrationId(clientRegistrationId); } if (principal == null) { return null; } OAuth2AuthorizedClient authorizedClient = this.authorizedClientService.loadAuthorizedClient( clientRegistrationId, principal.getName()); if (authorizedClient == null) { throw new ClientAuthorizationRequiredException(clientRegistrationId); } return OAuth2AccessToken.class.isAssignableFrom(parameter.getParameterType()) ? authorizedClient.getAccessToken() : authorizedClient; }

Target:
public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { OAuth2Client oauth2ClientAnnotation = parameter.getParameterAnnotation(OAuth2Client.class); Authentication principal = SecurityContextHolder.getContext().getAuthentication(); String clientRegistrationId = null; if (!StringUtils.isEmpty(oauth2ClientAnnotation.registrationId())) { clientRegistrationId = oauth2ClientAnnotation.registrationId(); } else if (!StringUtils.isEmpty(oauth2ClientAnnotation.value())) { clientRegistrationId = oauth2ClientAnnotation.value(); } else if (principal != null && OAuth2AuthenticationToken.class.isAssignableFrom(principal.getClass())) { clientRegistrationId = ((OAuth2AuthenticationToken) principal).getAuthorizedClientRegistrationId(); } if (StringUtils.isEmpty(clientRegistrationId)) { throw new IllegalArgumentException("Unable to resolve the Client Registration Identifier. " + "It must be provided via @OAuth2Client(\"client1\") or @OAuth2Client(registrationId = \"client1\")."); } if (ClientRegistration.class.isAssignableFrom(parameter.getParameterType())) { ClientRegistration clientRegistration = this.clientRegistrationRepository.findByRegistrationId(clientRegistrationId); if (clientRegistration == null) { throw new IllegalArgumentException("Unable to find ClientRegistration with registration identifier \"" + clientRegistrationId + "\"."); } return clientRegistration; } if (principal == null) { throw new IllegalStateException("Unable to resolve the Authorized Client with registration identifier \"" + clientRegistrationId + "\". An \"authenticated\" or \"unauthenticated\" session is required. " + "To allow for unauthenticated access, ensure HttpSecurity.anonymous() is configured."); } OAuth2AuthorizedClient authorizedClient = this.authorizedClientService.loadAuthorizedClient( clientRegistrationId, principal.getName()); if (authorizedClient == null) { throw new ClientAuthorizationRequiredException(clientRegistrationId); } return OAuth2AccessToken.class.isAssignableFrom(parameter.getParameterType()) ? authorizedClient.getAccessToken() : authorizedClient; }