Spring Reactive OAuth2: ຄຳຮ້ອງ token client_credentials ຜ່ານ proxy
ສຳລັບ client_credentials ໃນ Spring Security 6.5, ເຊື່ອມ WebClient ຂອງ token ຜ່ານຜູ້ໃຫ້ບໍລິການໄປຫາຜູ້ຈັດການ authorized-client ທີ່ໃຊ້ຕົວຈິງ.
ຊັບພະຍາກອນ WebClient ທີ່ຜ່ານ proxy ຍັງອາດລົ້ມເຫຼວກ່ອນການເອີ້ນ API ຖ້າການໄດ້ມາເຊິ່ງ token ໃຊ້ connector ອື່ນ. ສຳລັບກະແສ client_credentials ແບບ reactive ຂອງ 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 client ຂອງ token; provider.setAccessTokenResponseClient ກຳນົດມັນໃຫ້ຜູ້ໃຫ້ grant; manager.setAuthorizedClientProvider ຕິດຕັ້ງຜູ້ໃຫ້ນັ້ນ. ໃຊ້ຜູ້ຈັດການນີ້ໃນ OAuth filter ຕົວຈິງ ຫຼື workflow ຂອງ authorized-client.
HttpClient ແລະ ProxyProvider ເປັນປະເພດ Reactor Netty. WebClient ແລະ connector ຂອງມັນເປັນປະເພດ Spring WebFlux. ສະໜອງ ReactiveClientRegistrationRepository ທີ່ມີຢູ່ແລ້ວເປັນ registrations ແລະ ReactiveOAuth2AuthorizedClientService ເປັນ authorizedClients.
ຜູ້ໃຫ້ນີ້ຈັດການ client_credentials; ຮັກສາລຳດັບຜູ້ໃຫ້ທີ່ເໝາະສົມຖ້າຕ້ອງການ grant ອື່ນ. ຕົວຢ່າງບໍ່ມີບັນຊີ proxy; ມັນເປັນຂອງຊັ້ນ transport ບໍ່ແມ່ນ OAuth client ID/secret. ສຳລັບ token endpoint ສາທາລະນະທີ່ອະນຸຍາດຜ່ານຕົວກາງສາທາລະນະ ໃຫ້ເລືອກ host ແລະ port ຈາກ ບັນຊີ proxy HTTP.
ຕັ້ງຄ່າ connector ຂອງຊັບພະຍາກອນທີ່ຖືກປ້ອງກັນດ້ວຍ ເມື່ອການເອີ້ນ API ເຫຼົ່ານັ້ນຕ້ອງການເສັ້ນທາງ. ຄວາມສຳເລັດຂອງ token ແລະ API ເປັນຜົນແຍກກັນ.