Faodaidh goireas WebClient a thèid tro phrogsaidh fàilligeadh fhathast ron ghairm API aige mura h-eil an tòcan ga fhaighinn a' cleachdadh ceanglaiche eile. Airson sruth reactive client_credentials Spring Security 6.5, ceangail na trì pìosan:

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);

Bheir tokens.setWebClient an ceanglaiche HTTP tòcain; bheir provider.setAccessTokenResponseClient don t-solaraiche tabhartais e; stàlaicheas manager.setAuthorizedClientProvider an solaraiche sin. Cleachd am manaidsear seo anns a' chriathradair OAuth fhìor no ann an sruth-obrach authorized-client.

Is seòrsaichean Reactor Netty a th' ann an HttpClient agus ProxyProvider. Is seòrsaichean Spring WebFlux a th' ann an WebClient agus a cheanglaiche. Thoir an ReactiveClientRegistrationRepository a th' ann mar registrations agus an ReactiveOAuth2AuthorizedClientService mar authorizedClients.

Làimhsicheas an solaraiche seo client_credentials; cùm slabhraidh sholaraichean iomchaidh ma tha tabhartasan eile a dhìth. Chan eil cunntas progsaidh san eisimpleir; bhuineadh sin don ghiùlan, chan ann do OAuth client ID/secret. Airson ceann-uidhe tòcain poblach a cheadaichear tro eadar-mheadhanair poblach, tagh ostair agus port bhon liosta progsaidh HTTP.

Cuir ceanglaiche a' ghoireis dìonta air dòigh cuideachd nuair a dh'fheumas na gairmean API sin an t-slighe. Tha soirbheachadh tòcain agus soirbheachadh API nan toraidhean air leth.

Artaigilean co-cheangailte