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-webmvc/filters/tokenrelay.adoc
+15-19Lines changed: 15 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -6,25 +6,27 @@ 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
-
////
10
-
TODO: support TokenRelay clientRegistrationId
11
9
Spring Cloud Gateway Server MVC can forward OAuth2 access tokens downstream to the services
12
10
it is proxying using the `TokenRelay` filter.
13
11
14
12
The `TokenRelay` filter takes one optional parameter, `clientRegistrationId`.
15
13
The following example configures a `TokenRelay` filter:
16
14
17
-
.App.java
15
+
.RouteConfiguration.java
18
16
[source,java]
19
17
----
20
18
21
-
@Bean
22
-
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
23
-
return builder.routes()
24
-
.route("resource", r -> r.path("/resource")
25
-
.filters(f -> f.tokenRelay("myregistrationid"))
26
-
.uri("http://localhost:9000"))
19
+
@Configuration
20
+
class RouteConfiguration {
21
+
22
+
@Bean
23
+
public RouterFunction<ServerResponse> gatewayRouterFunctionsTokenRelay() {
24
+
return route("resource")
25
+
.GET("/resource", http())
26
+
.before(uri("https://localhost:9000"))
27
+
.filter(tokenRelay("myregistrationid"))
27
28
.build();
29
+
}
28
30
}
29
31
----
30
32
@@ -46,19 +48,13 @@ spring:
46
48
----
47
49
48
50
The example above specifies a `clientRegistrationId`, which can be used to obtain and forward an OAuth2 access token for any available `ClientRegistration`.
49
-
////
50
51
51
52
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:
53
+
To add this functionality to the gateway, you can omit the `clientRegistrationId` parameter like this:
// The filter extracts an OAuth2 access token from the currently authenticated user for the provided `clientRegistrationId`.
104
-
// If no `clientRegistrationId` is provided,
105
-
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.
99
+
The filter extracts an OAuth2 access token from the currently authenticated user for the provided `clientRegistrationId`.
100
+
If no `clientRegistrationId` is provided,
101
+
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.
106
102
107
103
//For a full working sample see https://github.com/spring-cloud-samples/sample-gateway-oauth2login[this project].
Copy file name to clipboardExpand all lines: spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/filter/TokenRelayFilterFunctions.java
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -39,6 +39,7 @@ public static HandlerFilterFunction<ServerResponse, ServerResponse> tokenRelay()
0 commit comments