Spring Reactive OAuth2: codsiyada token client_credentials ee proxy
Client_credentials-ka Spring Security 6.5, ku xidh WebClient-ka token-ka iyada oo loo marayo bixiyaha maamulaha authorized-client ee dhab ahaan la isticmaalo.
Kheyraadka WebClient ee mara proxy wali wuu fashilmi karaa ka hor wicitaanka API haddii helitaanka token-ku isticmaalo connector kale. Socodka client_credentials ee falcelinta Spring Security 6.5, isku xidh saddexda qaybood:
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 waxay u qoondeysaa macmiilka HTTP ee token-ka; provider.setAccessTokenResponseClient waxay u qoondeysaa bixiyaha grant-ka; manager.setAuthorizedClientProvider waxay rakibaa bixiyahaas. Isticmaal maamulahan filter-ka OAuth ee dhabta ah ama socodka shaqada authorized-client.
HttpClient iyo ProxyProvider waa noocyada Reactor Netty. WebClient iyo connector-keeda waa noocyada Spring WebFlux. Bixi ReactiveClientRegistrationRepository jira sida registrations iyo ReactiveOAuth2AuthorizedClientService sida authorizedClients.
Bixiyahan wuxuu maareeyaa client_credentials; hay silsilad bixiye ku habboon haddii grants kale loo baahan yahay. Tusaalahu ma laha akoon proxy; taas waxay ka tirsanaan lahayd gaadiidka ee ma aha OAuth client ID/secret. Token endpoint dadweyne oo lagu oggolaaday dhexdhexaadiye dadweyne, dooro host iyo port ka liiska proxy HTTP.
Sidoo kale habee connector-ka kheyraadka la ilaaliyay marka wicitaannadaas API ay u baahan yihiin marinka. Guusha token-ka iyo tan API waa natiijooyin gooni ah.