Spring Reactive OAuth2፦ በ proxy የሚደረግ client_credentials ቶክን ጥያቄዎች
በ Spring Security 6.5 client_credentials ውስጥ የቶክን WebClientን በአቅራቢው በኩል በትክክል ወደሚጠቀመው authorized-client አስተዳዳሪ ያገናኙ።
በ proxy የሚያልፍ ሀብት WebClient የቶክን ማግኘት ሌላ connector ቢጠቀም ከ 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 እና connectorው የ Spring WebFlux ዓይነቶች ናቸው። ያለውን ReactiveClientRegistrationRepository እንደ registrations እና ReactiveOAuth2AuthorizedClientService እንደ authorizedClients ያቅርቡ።
ይህ አቅራቢ client_credentials ያስተናግዳል፤ ሌሎች grants ካስፈለጉ ተስማሚ የአቅራቢ ሰንሰለት ይጠብቁ። ምሳሌው የ proxy መለያ የለውም፤ ይህ ከ OAuth client ID/secret ይልቅ የ transport ጉዳይ ነው። በሕዝባዊ መካከለኛ የሚፈቀድ ሕዝባዊ token endpoint ካለ፣ ከ HTTP proxy ዝርዝር አስተናጋጅና ፖርት ይምረጡ።
እነዚያ API ጥሪዎች መንገዱን ሲፈልጉ የተጠበቀውን ሀብት connectorም ያዋቅሩ። የቶክንና የ API ስኬት የተለያዩ ውጤቶች ናቸው።