Spring Reactive OAuth2: คำขอโทเคน client_credentials ผ่านพร็อกซี
สำหรับ client_credentials ใน Spring Security 6.5 ให้เชื่อม WebClient ของโทเคนผ่านผู้ให้บริการเข้ากับตัวจัดการ authorized-client ที่ใช้งานจริง
ทรัพยากร WebClient ที่ผ่านพร็อกซียังล้มเหลวก่อนการเรียก API ได้ หากการรับโทเคนใช้ตัวเชื่อมอื่น สำหรับโฟลว์ client_credentials แบบรีแอกทีฟของ Spring Security 6.5 ให้เชื่อมทั้งสามส่วน:
HttpClient route = HttpClient.create()
.proxy(p -> p.type(ProxyProvider.Proxy.HTTP)
.host("proxy.example").port(8080));
WebClient tokenHttp = WebClient.builder()
.clientConnector(new ReactorClientHttpConnector(route))
.build();
var tokens = new WebClientReactiveClientCredentialsTokenResponseClient();
tokens.setWebClient(tokenHttp);
var provider = new ClientCredentialsReactiveOAuth2AuthorizedClientProvider();
provider.setAccessTokenResponseClient(tokens);
var manager = new AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager(
registrations, authorizedClients);
manager.setAuthorizedClientProvider(provider);tokens.setWebClient กำหนดไคลเอนต์ HTTP ของโทเคน; provider.setAccessTokenResponseClient กำหนดให้กับผู้ให้ grant; manager.setAuthorizedClientProvider ติดตั้งผู้ให้บริการนั้น ใช้ตัวจัดการนี้ในฟิลเตอร์ OAuth จริงหรือเวิร์กโฟลว์ authorized-client
HttpClient และ ProxyProvider เป็นชนิดของ Reactor Netty WebClient และตัวเชื่อมของมันเป็นชนิดของ Spring WebFlux ส่ง ReactiveClientRegistrationRepository ที่มีอยู่เป็น registrations และ ReactiveOAuth2AuthorizedClientService เป็น authorizedClients
ผู้ให้บริการนี้จัดการ client_credentials; รักษาลำดับผู้ให้บริการที่เหมาะสมหากต้องใช้ grant อื่น ตัวอย่างไม่มีบัญชีพร็อกซี ซึ่งจะอยู่ในชั้นการรับส่งไม่ใช่ OAuth client ID/secret สำหรับ token endpoint สาธารณะที่อนุญาตผ่านตัวกลางสาธารณะ ให้เลือก host และ port จาก รายการพร็อกซี HTTP
กำหนดค่าตัวเชื่อมของทรัพยากรที่ได้รับการป้องกันด้วยเมื่อการเรียก API เหล่านั้นต้องใช้เส้นทาง ความสำเร็จของโทเคนและของ API เป็นผลลัพธ์แยกกัน