പ്രോക്സി വഴി പോകുന്ന ഒരു റിസോഴ്സ് WebClient ടോക്കൺ നേട്ടം മറ്റൊരു കണക്ടർ ഉപയോഗിക്കുന്നുവെങ്കിൽ API വിളിക്ക് മുമ്പ് പരാജയപ്പെടാം. Spring Security 6.5-ലെ റിയാക്ടീവ് client_credentials ഫ്ലോയ്ക്ക് മൂന്ന് ഭാഗങ്ങളും ബന്ധിപ്പിക്കുക:

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-ന് HTTP പ്രോക്സി പട്ടികയിൽ നിന്ന് host-ഉം port-ഉം തിരഞ്ഞെടുക്കുക.

ആ API വിളികൾക്ക് റൂട്ട് ആവശ്യമുള്ളപ്പോൾ സംരക്ഷിത റിസോഴ്സിന്റെ കണക്ടറും കോൺഫിഗർ ചെയ്യുക. ടോക്കൺ വിജയവും API വിജയവും വെവ്വേറെ ഫലങ്ങളാണ്.

അനുബന്ധ ലേഖനങ്ങൾ