小编bra*_*ley的帖子

Spring 5 中机密客户的 PKCE(非反应式)

我正在尝试在 Spring Boot 5 中的 oAuth 客户端上启用 PKCE。我可以找到的示例适用于反应式客户端,如下所示:

SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http,    ReactiveClientRegistrationRepository clientRegistrationRepository) {
        DefaultServerOAuth2AuthorizationRequestResolver pkceResolver = new DefaultServerOAuth2AuthorizationRequestResolver(clientRegistrationRepository);
        pkceResolver.setAuthorizationRequestCustomizer(OAuth2AuthorizationRequestCustomizers.withPkce());

http.oauth2Login(login -> login
    .authorizationRequestResolver(pkceResolver)

Run Code Online (Sandbox Code Playgroud)

我尝试将其转换为等效的 servlet,但 oAuthLoginConfigurer 没有authorizationRequestResolver设置 PKCE 解析器的方法。

这就是我要做的:

  @Bean
  public SecurityFilterChain filterChain(HttpSecurity http
          ,ClientRegistrationRepository repo
  ) 
  throws Exception {

    var resolver = new DefaultOAuth2AuthorizationRequestResolver(repo,"https://myoauthserver.com");
    resolver.setAuthorizationRequestCustomizer(OAuth2AuthorizationRequestCustomizers.withPkce());
    
    http
        .authorizeRequests(a -> a
            .antMatchers("/").permitAll()
            .anyRequest().authenticated())
        .oauth2Login(); // doesn't have the authorizationRequestResolver method like reactive



    return http.build();
  }

Run Code Online (Sandbox Code Playgroud)

有什么想法可以让 servlet 工作吗?

servlets oauth-2.0 spring-boot pkce

1
推荐指数
1
解决办法
557
查看次数

标签 统计

oauth-2.0 ×1

pkce ×1

servlets ×1

spring-boot ×1