Improve TokenRelay filter documentation when Gateway acts as a BFF

Đang mở
#4,355 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@ruthst00 đang làm issue này rồi.

Từ ngày 10/11/2026.

  • #4367 của @ruthst00 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
Nửa ngày
Mức phù hợp với người mới
58/100
Loại issue
Tài liệu
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java, spring-boot

Hướng nghiên cứu

The target is the TokenRelay filter reference page for the WebMVC gateway, which is documentation, not code. Read the existing filter section, then compare it with the reporter's SecurityFilterChain example, which sets oauth2Login success handling, oidcLogout, a logout success handler, and csrf.spa(). Done means the page explains which of these settings a BFF needs for post-login and post-logout redirects. The multi-frontend whitelist idea is a design question and is out of scope.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

waiting-for-triage

Here, using BFF and token relay patterns becomes popular (see https://datatracker.ietf.org/doc/rfc10017).

TokenRelayFilter works but requires some tweaks for proper redirection after login and logout.

I think this page https://docs.spring.io/spring-cloud-gateway/reference/spring-cloud-gateway-server-webmvc/filters/tokenrelay.html could give more details about the settings required to have a working BFF.

Here is what I have:

@Bean
SecurityFilterChain oauth2SecurityFilterChain(HttpSecurity http, ClientRegistrationRepository registrations) {
	String frontendUrl = "http://localhost:9000";

	var authenticationSuccessHandler = new SimpleUrlAuthenticationSuccessHandler(frontendUrl);
	var logoutSuccessHandler = new OidcClientInitiatedLogoutSuccessHandler(registrations);
	logoutSuccessHandler.setPostLogoutRedirectUri(frontendUrl);

	http.oauth2Login(cust -> cust.successHandler(authenticationSuccessHandler));
	http.oauth2Client(withDefaults());
	http.oidcLogout(oidc -> oidc.backChannel(Customizer.withDefaults()));
	http.logout(cust -> cust.logoutSuccessHandler(logoutSuccessHandler));
	http.csrf(x -> x.spa());

	return http.build();
}

The frontend URL must be a valid redirect URL (OIDC client settings) otherwise redirect after logout fails.

Using

var logoutSuccessHandler =  new SimpleUrlLogoutSuccessHandler();
logoutSuccessHandler.setDefaultTargetUrl(frontendUrl);

is a kind of trap because it invalidates the session at the gateway level but does not call OIDC server so at the OIDC server level the user is still logged.

The frontend url can be declared as a custom property but there will still be is a 1-1 relationship between the BFF and the frontend. It respects the "backend for frontend" semantic ("frontend" is singular) but frontend url could be transmitted in the URL when the client logs in (GET on http://bff/oauth2/authorization/+registrationid) and saved in session for the final redirection. A whitelist of approved frontends could be declared somewhere. Adding a BFF make the infrastructure more complex so if a single BFF can serve several frontends it fosters adoption.

Ngôn ngữ chính
Java
Star
4.9k
Fork
3.5k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
9

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của spring-cloud/spring-cloud-gateway

Tất cả issue của spring-cloud/spring-cloud-gateway

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.