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
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/spring-cloud-gateway-server-mvc/filters/tokenrelay.adoc
+38-30Lines changed: 38 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,9 @@ forwards the incoming token to outgoing resource requests. The
6
6
consumer can be a pure Client (like an SSO application) or a Resource
7
7
Server.
8
8
9
-
Spring Cloud Gateway can forward OAuth2 access tokens downstream to the services
9
+
////
10
+
TODO: support TokenRelay clientRegistrationId
11
+
Spring Cloud Gateway Server MVC can forward OAuth2 access tokens downstream to the services
10
12
it is proxying using the `TokenRelay` filter.
11
13
12
14
The `TokenRelay` filter takes one optional parameter, `clientRegistrationId`.
@@ -44,21 +46,28 @@ spring:
44
46
----
45
47
46
48
The example above specifies a `clientRegistrationId`, which can be used to obtain and forward an OAuth2 access token for any available `ClientRegistration`.
49
+
////
47
50
48
-
Spring Cloud Gateway can also forward the OAuth2 access token of the currently authenticated user `oauth2Login()` is used to authenticate the user.
49
-
To add this functionality to the gateway, you can omit the `clientRegistrationId` parameter like this:
51
+
Spring Cloud Gateway Server MVC can forward the OAuth2 access token of the currently authenticated user `oauth2Login()` is used to authenticate the user.
52
+
//To add this functionality to the gateway, you can omit the `clientRegistrationId` parameter like this:
50
53
51
-
.App.java
54
+
.RouteConfiguration.java
52
55
[source,java]
53
56
----
54
-
55
-
@Bean
56
-
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
How does it work? The {github-code}/src/main/java/org/springframework/cloud/gateway/security/TokenRelayGatewayFilterFactory.java[filter]
91
-
extracts an OAuth2 access token from the currently authenticated user for the provided `clientRegistrationId`.
92
-
If no `clientRegistrationId` is provided, the currently authenticated user's own access token (obtained during login) is used.
93
-
In either case, the extracted access token is placed in a request header for the downstream requests.
100
+
How does it work?
101
+
// The filter extracts an OAuth2 access token from the currently authenticated user for the provided `clientRegistrationId`.
102
+
// If no `clientRegistrationId` is provided,
103
+
The currently authenticated user's own access token (obtained during login) is used and the extracted access token is placed in a request header for the downstream requests.
94
104
95
-
For a full working sample see https://github.com/spring-cloud-samples/sample-gateway-oauth2login[this project].
105
+
//For a full working sample see https://github.com/spring-cloud-samples/sample-gateway-oauth2login[this project].
96
106
97
-
NOTE: A `TokenRelayGatewayFilterFactory` bean will only be created if the proper `spring.security.oauth2.client.*` properties are set which will trigger creation of a `ReactiveClientRegistrationRepository` bean.
107
+
NOTE: The Token Relay filter will only work if the proper `spring.security.oauth2.client.*` properties are set which will trigger creation of a `OAuth2AuthorizedClientManager` bean.
98
108
99
-
NOTE: The default implementation of `ReactiveOAuth2AuthorizedClientService` used by `TokenRelayGatewayFilterFactory`
100
-
uses an in-memory data store. You will need to provide your own implementation `ReactiveOAuth2AuthorizedClientService`
109
+
NOTE: The default implementation used by the Token Relay filter
110
+
uses an in-memory data store. You will need to provide your own implementation `OAuth2AuthorizedClientService`
0 commit comments