Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring security 如何使用OAuth2AuthorizedClientManager与OAuth2AuthorizedClientService_Spring Security_Spring Security Oauth2 - Fatal编程技术网

Spring security 如何使用OAuth2AuthorizedClientManager与OAuth2AuthorizedClientService

Spring security 如何使用OAuth2AuthorizedClientManager与OAuth2AuthorizedClientService,spring-security,spring-security-oauth2,Spring Security,Spring Security Oauth2,我正在SpringBoot2中使用SpringSecurity5实现一个OAuth2客户机。我不清楚应该如何使用vs。OAuth2AuthorizedClientManger是在5.2中引入的,因此它是一个较新的API,但OAuth2AuthorizedClientService似乎是一个更完善的客户端接口。我期望OAuth2AuthorizedClient服务可以通过OAuth2AuthorizedClient管理器配置,但事实似乎并非如此 重要的是,我需要定制OAuth2AccessToke

我正在SpringBoot2中使用SpringSecurity5实现一个OAuth2客户机。我不清楚应该如何使用vs。OAuth2AuthorizedClientManger是在5.2中引入的,因此它是一个较新的API,但OAuth2AuthorizedClientService似乎是一个更完善的客户端接口。我期望
OAuth2AuthorizedClient服务可以通过
OAuth2AuthorizedClient管理器配置,但事实似乎并非如此

重要的是,我需要定制
OAuth2AccessTokenResponseHttpMessageConverter
,以定制发送到授权服务器的请求。这在
OAuth2AuthorizedClientManager
上提供,但我无法从
oauth2authorizedclientservice
中找到如何实现这一点

注册OAuth2Access TokenResponseHttpMessageConverter的代码

  @Bean
  public OAuth2AuthorizedClientManager authorizedClientManager(ClientRegistrationRepository clientRegistrationRepository,
                                                               OAuth2AuthorizedClientService oAuth2AuthorizedClientService) {

    DefaultClientCredentialsTokenResponseClient defaultClientCredentialsTokenResponseClient = new DefaultClientCredentialsTokenResponseClient();
    defaultClientCredentialsTokenResponseClient.setRequestEntityConverter(new OAuth2ClientCredentialsGrantJWTAssertionRequestEntityConverter());
    OAuth2AuthorizedClientProvider authorizedClientProvider =
        OAuth2AuthorizedClientProviderBuilder.builder()
          .clientCredentials(clientCredentialsGrantBuilder -> {

            clientCredentialsGrantBuilder.accessTokenResponseClient(defaultClientCredentialsTokenResponseClient);
          })
          .build();
    OAuth2AuthorizedClientManager authorizedClientManager
        = new AuthorizedClientServiceOAuth2AuthorizedClientManager(clientRegistrationRepository, oAuth2AuthorizedClientService);
    ((AuthorizedClientServiceOAuth2AuthorizedClientManager)authorizedClientManager).setAuthorizedClientProvider(authorizedClientProvider);
    return authorizedClientManager;
  }

您需要对发送到授权服务器的请求进行哪些定制?@peater,我们的授权服务器使用JWT断言()如果您需要发送自定义请求,我想您应该自定义
OAuth2AuthorizationCodeGrantRequestEntityConverter
这就是
DefaultClientCredentialsTokenResponseClient
的功能,而不是客户端I和客户端机密。