WebClient OAuth2 Support for defaultClientRegistrationId
Fixes: gh-5872
This commit is contained in:
@@ -38,7 +38,9 @@ WebClient webClient(ReactiveClientRegistrationRepository clientRegistrations,
|
||||
ServerOAuth2AuthorizedClientExchangeFilterFunction oauth =
|
||||
new ServerOAuth2AuthorizedClientExchangeFilterFunction(clientRegistrations, authorizedClients);
|
||||
// (optional) explicitly opt into using the oauth2Login to provide an access token implicitly
|
||||
oauth.setDefaultOAuth2AuthorizedClient(true);
|
||||
// oauth.setDefaultOAuth2AuthorizedClient(true);
|
||||
// (optional) set a default ClientRegistration.registrationId
|
||||
// oauth.setDefaultClientRegistrationId("client-registration-id");
|
||||
return WebClient.builder()
|
||||
.filter(oauth)
|
||||
.build();
|
||||
@@ -48,7 +50,8 @@ WebClient webClient(ReactiveClientRegistrationRepository clientRegistrations,
|
||||
[[webclient-implicit]]
|
||||
== Implicit OAuth2AuthorizedClient
|
||||
|
||||
If we set `defaultOAuth2AuthorizedClient` to `true` in our setup and the user authenticated with oauth2Login (i.e. OIDC), then the current authentication is used to automatically provide the access token.
|
||||
If we set `defaultOAuth2AuthorizedClient` to `true`in our setup and the user authenticated with oauth2Login (i.e. OIDC), then the current authentication is used to automatically provide the access token.
|
||||
Alternatively, if we set `defaultClientRegistrationId` to a valid `ClientRegistration` id, that registration is used to provide the access token.
|
||||
This is convenient, but in environments where not all endpoints should get the access token, it is dangerous (you might provide the wrong access token to an endpoint).
|
||||
|
||||
[source,java]
|
||||
|
||||
@@ -39,9 +39,11 @@ WebClient webClient(ReactiveClientRegistrationRepository clientRegistrations,
|
||||
ServerOAuth2AuthorizedClientExchangeFilterFunction oauth =
|
||||
new ServerOAuth2AuthorizedClientExchangeFilterFunction(clientRegistrations, authorizedClients);
|
||||
// (optional) explicitly opt into using the oauth2Login to provide an access token implicitly
|
||||
oauth.setDefaultOAuth2AuthorizedClient(true);
|
||||
// oauth.setDefaultOAuth2AuthorizedClient(true);
|
||||
// (optional) set a default ClientRegistration.registrationId
|
||||
// oauth.setDefaultClientRegistrationId("client-registration-id");
|
||||
return WebClient.builder()
|
||||
.filter(oauth)
|
||||
.apply(oauth2.oauth2Configuration())
|
||||
.build();
|
||||
}
|
||||
----
|
||||
@@ -50,6 +52,7 @@ WebClient webClient(ReactiveClientRegistrationRepository clientRegistrations,
|
||||
== Implicit OAuth2AuthorizedClient
|
||||
|
||||
If we set `defaultOAuth2AuthorizedClient` to `true` in our setup and the user authenticated with oauth2Login (i.e. OIDC), then the current authentication is used to automatically provide the access token.
|
||||
Alternatively, if we set `defaultClientRegistrationId` to a valid `ClientRegistration` id, that registration is used to provide the access token.
|
||||
This is convenient, but in environments where not all endpoints should get the access token, it is dangerous (you might provide the wrong access token to an endpoint).
|
||||
|
||||
[source,java]
|
||||
|
||||
Reference in New Issue
Block a user