我使用 Angular 作为客户端的 FE,而在 BE 中,身份验证和授权过程是通过 Oauth2 授权服务器使用 Spring 提供的 formLogin 进行登录(也使用 Google 登录)完成的,我想知道这个表单是否必须在其中BE 或者我可以在 FE 中使用自定义表单并通过 http 发送登录信息吗?
这是我的配置
@Bean
@Order(2)
public SecurityFilterChain webSecurityFilterChain(HttpSecurity http) throws Exception {
FederatedIdentityConfigurer federatedIdentityConfigurer = new FederatedIdentityConfigurer()
.oauth2UserHandler(new UserRepositoryOAuth2UserHandler());
http
.authorizeHttpRequests(authorize ->
authorize
.requestMatchers("/login").permitAll()
.anyRequest().authenticated()
)
.formLogin(Customizer.withDefaults())
.apply(federatedIdentityConfigurer);
return http.build();
}
授权服务器通常会公开自定义表单的方法(至少是 CSS),但只需阅读
authorization_code
流程,您就会明白为什么此表单必须由授权服务器管理,而不是由 OAuth2 客户端或 Angular 前端管理 - end(不应是 OAuth2 客户端)。
阅读我的教程介绍,了解最基本的 OAuth2 背景。