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
Now that you're in possession of a bearer token, it might be handy to pass that to downstream services.
1006
+
This is quite simple with `{security-api-url}org/springframework/security/oauth2/server/resource/web/reactive/function/client/ServerBearerExchangeFilterFunction.html[ServerBearerExchangeFilterFunction]`, which you can see in the following example:
1007
+
1008
+
[source,java]
1009
+
----
1010
+
@Bean
1011
+
public WebClient rest() {
1012
+
return WebClient.builder()
1013
+
.filter(new ServerBearerExchangeFilterFunction())
1014
+
.build();
1015
+
}
1016
+
----
1017
+
1018
+
When the above `WebClient` is used to perform requests, Spring Security will look up the current `Authentication` and extract any `{security-api-url}org/springframework/security/oauth2/core/AbstractOAuth2Token.html[AbstractOAuth2Token]` credential.
1019
+
Then, it will propagate that token in the `Authorization` header.
In this case, the filter will fall back and simply forward the request onto the rest of the web filter chain.
1045
+
1046
+
[NOTE]
1047
+
Unlike the https://docs.spring.io/spring-security/site/docs/current-SNAPSHOT/api/org/springframework/security/oauth2/client/web/reactive/function/client/ServerOAuth2AuthorizedClientExchangeFilterFunction.html[OAuth 2.0 Client filter function], this filter function makes no attempt to renew the token, should it be expired.
1048
+
To obtain this level of support, please use the OAuth 2.0 Client filter.
Thus far we have only taken a look at the most basic authentication configuration.
1152
1152
Let's take a look at a few slightly more advanced options for configuring authentication.
1153
+
1154
+
=== Bearer Token Propagation
1155
+
1156
+
Now that you're in possession of a bearer token, it might be handy to pass that to downstream services.
1157
+
This is quite simple with `{security-api-url}org/springframework/security/oauth2/server/resource/web/reactive/function/client/ServletBearerExchangeFilterFunction.html[ServletBearerExchangeFilterFunction]`, which you can see in the following example:
When the above `WebClient` is used to perform requests, Spring Security will look up the current `Authentication` and extract any `{security-api-url}org/springframework/security/oauth2/core/AbstractOAuth2Token.html[AbstractOAuth2Token]` credential.
1170
+
Then, it will propagate that token in the `Authorization` header.
In this case, the filter will fall back and simply forward the request onto the rest of the web filter chain.
1198
+
1199
+
[NOTE]
1200
+
Unlike the https://docs.spring.io/spring-security/site/docs/current-SNAPSHOT/api/org/springframework/security/oauth2/client/web/reactive/function/client/ServletOAuth2AuthorizedClientExchangeFilterFunction.html[OAuth 2.0 Client filter function], this filter function makes no attempt to renew the token, should it be expired.
1201
+
To obtain this level of support, please use the OAuth 2.0 Client filter.
1202
+
1203
+
==== `RestTemplate` support
1204
+
1205
+
There is no dedicated support for `RestTemplate` at the moment, but you can achieve propagation quite simply with your own interceptor:
0 commit comments