પ્રોક્સી દ્વારા જતું સંસાધન 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 ની સફળતા અલગ પરિણામો છે.

સંબંધિત લેખો