Skip to content

Commit 67d3e4c

Browse files
author
Steve Riesenberg
committed
Merge branch '6.1.x'
2 parents 621ab3e + a2d1fcf commit 67d3e4c

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

docs/modules/ROOT/pages/servlet/oauth2/client/authorized-clients.adoc

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,63 @@ fun index(): String {
201201
======
202202
<1> `clientRegistrationId()` is a `static` method in `ServletOAuth2AuthorizedClientExchangeFilterFunction`.
203203

204+
The following code shows how to set an `Authentication` as a request attribute:
205+
206+
[tabs]
207+
======
208+
Java::
209+
+
210+
[source,java,role="primary"]
211+
----
212+
@GetMapping("/")
213+
public String index() {
214+
String resourceUri = ...
215+
216+
Authentication anonymousAuthentication = new AnonymousAuthenticationToken(
217+
"anonymous", "anonymousUser", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));
218+
String body = webClient
219+
.get()
220+
.uri(resourceUri)
221+
.attributes(authentication(anonymousAuthentication)) <1>
222+
.retrieve()
223+
.bodyToMono(String.class)
224+
.block();
225+
226+
...
227+
228+
return "index";
229+
}
230+
----
231+
232+
Kotlin::
233+
+
234+
[source,kotlin,role="secondary"]
235+
----
236+
@GetMapping("/")
237+
fun index(): String {
238+
val resourceUri: String = ...
239+
240+
val anonymousAuthentication: Authentication = AnonymousAuthenticationToken(
241+
"anonymous", "anonymousUser", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"))
242+
val body: String = webClient
243+
.get()
244+
.uri(resourceUri)
245+
.attributes(authentication(anonymousAuthentication)) <1>
246+
.retrieve()
247+
.bodyToMono()
248+
.block()
249+
250+
...
251+
252+
return "index"
253+
}
254+
----
255+
======
256+
<1> `authentication()` is a `static` method in `ServletOAuth2AuthorizedClientExchangeFilterFunction`.
257+
258+
[WARNING]
259+
It is recommended to be cautious with this feature since all HTTP requests will receive an access token bound to the provided principal.
260+
204261

205262
=== Defaulting the Authorized Client
206263

0 commit comments

Comments
 (0)