You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
54
85
Alternatively, if we set `defaultClientRegistrationId` to a valid `ClientRegistration` id, that registration is used to provide the access token.
55
86
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).
56
87
57
-
[source,java]
88
+
====
89
+
.Java
90
+
[source,java,role="primary"]
58
91
----
59
92
Mono<String> body = this.webClient
60
93
.get()
@@ -63,14 +96,27 @@ Mono<String> body = this.webClient
63
96
.bodyToMono(String.class);
64
97
----
65
98
99
+
.Kotlin
100
+
[source,kotlin,role="secondary"]
101
+
----
102
+
val body: Mono<String> = webClient
103
+
.get()
104
+
.uri(this.uri)
105
+
.retrieve()
106
+
.bodyToMono()
107
+
----
108
+
====
109
+
66
110
[[webclient-explicit]]
67
111
== Explicit OAuth2AuthorizedClient
68
112
69
113
The `OAuth2AuthorizedClient` can be explicitly provided by setting it on the requests attributes.
70
114
In the example below we resolve the `OAuth2AuthorizedClient` using Spring WebFlux or Spring MVC argument resolver support.
71
115
However, it does not matter how the `OAuth2AuthorizedClient` is resolved.
Alternatively, it is possible to specify the `clientRegistrationId` on the request attributes and the `WebClient` will attempt to lookup the `OAuth2AuthorizedClient`.
90
151
If it is not found, one will automatically be acquired.
91
152
92
-
[source,java]
153
+
====
154
+
.Java
155
+
[source,java,role="primary"]
93
156
----
94
157
Mono<String> body = this.webClient
95
158
.get()
@@ -98,3 +161,15 @@ Mono<String> body = this.webClient
0 commit comments