【发布时间】:2019-03-07 22:54:51
【问题描述】:
我的问题特定于 spring-security 5.1.0 并使用 Spring WebClient。我在使用 Spring Boot 2.1.0 的服务器环境中工作。这个question 可能已经被问过了,但当时无法回答。
阅读 spring-security 5.1.0 release notes,似乎他们已经添加了对 client_credentials 身份验证流程的支持,特别是将其添加到 WebClient Bean 中,因此最终用户不必担心身份验证令牌。我正试图做到这一点,但 API/文档让我完全迷失了。我目前的工作如下...
private ClientRegistration clientRegistration() {
return ClientRegistration.withRegistrationId("registration-id")
.clientId("client-id")
.clientSecret("secret")
.tokenUri("token-url")
.clientAuthenticationMethod(ClientAuthenticationMethod.BASIC)
.authorizationGrantType(AuthorizationGrantType.CLIENT_CREDENTIALS)
.scope("scopes")
.build();
}
@Bean
public WebClient webClient() {
ClientRegistrationRepository clientRegistrationRepository = new InMemoryClientRegistrationRepository(this.clientRegistration());
OAuth2AuthorizedClientService oAuth2AuthorizedClientService = new InMemoryOAuth2AuthorizedClientService(clientRegistrationRepository);
# These are unused ^ but pieces of documentation seem to indicate they are required
return WebClient.builder()
.filter(new ServerOAuth2AuthorizedClientExchangeFilterFunction()) # this requires 2 arguments that I do not have
.build();
}
我的最终目标是能够在任何地方自动装配 WebClient bean,并且只需发出自动添加了 bearer 身份验证的请求。
【问题讨论】:
标签: java spring spring-security spring-security-oauth2