Spring Jhipster OIDC授权代码配置

Spring Jhipster OIDC授权代码配置,spring,spring-boot,jhipster,keycloak,spring-security-oauth2,Spring,Spring Boot,Jhipster,Keycloak,Spring Security Oauth2,第一,我的英语不是很好。所以我很抱歉,如果这可能会让你混淆我的问题 我正在使用jhipster 6.10.3 我的应用程序将授权代码流与KeyClope一起使用 我在jhipster安全配置中看到 http .csrf() .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) .and() .addFilterBefore(corsFilter, CsrfFi

第一,我的英语不是很好。所以我很抱歉,如果这可能会让你混淆我的问题

我正在使用jhipster 6.10.3

我的应用程序将授权代码流与KeyClope一起使用

我在jhipster安全配置中看到

http
        .csrf()
        .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
    .and()
        .addFilterBefore(corsFilter, CsrfFilter.class)
        .exceptionHandling()
            .authenticationEntryPoint(problemSupport)
            .accessDeniedHandler(problemSupport)
    .and()
        .headers()
        .contentSecurityPolicy("default-src 'self'; frame-src 'self' data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://storage.googleapis.com; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:")
    .and()
        .referrerPolicy(ReferrerPolicyHeaderWriter.ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN)
    .and()
        .featurePolicy("geolocation 'none'; midi 'none'; sync-xhr 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope 'none'; speaker 'none'; fullscreen 'self'; payment 'none'")
    .and()
        .frameOptions()
        .deny()
    .and()
        .authorizeRequests()
        .antMatchers("/api/auth-info").permitAll()
        .antMatchers("/api/**").authenticated()
        .antMatchers("/management/health").permitAll()
        .antMatchers("/management/info").permitAll()
        .antMatchers("/management/prometheus").permitAll()
        .antMatchers("/management/**").hasAuthority(AuthoritiesConstants.ADMIN)
    .and()
        .oauth2Login()
    .and()
        .oauth2ResourceServer()
            .jwt()
            .jwtAuthenticationConverter(authenticationConverter())
            .and()
        .and()
            .oauth2Client();
他们配置authenticationEntryPoint使用zalando提供的problemSupport

当我访问一个安全的API时。它返回结果:

{
  "type" : "https://www.jhipster.tech/problem/problem-with-message",
  "title" : "Unauthorized",
  "status" : 401,
  "detail" : "Full authentication is required to access this resource",
  "path" : "/api/users",
  "message" : "error.http.401"
}
然后,如果我删除此配置:authenticationEntryPoint(problemSupport)

它将重定向到KeyClope登录

我的问题是:

我应该为我的应用程序配置什么?

  • 在keydeporetwo客户端进行配置。前端应用程序的访问类型为Public。一个访问类型为机密的用于后端应用程序。->未经授权时,我的FE应用程序将重定向到KeyClope

  • 使用访问类型机密在keydepot配置一个客户端。并删除此配置:authenticationEntryPoint(problemSupport)。->未经授权时,我的BE应用程序将重定向到KeyClope


  • 我是否应该配置任何不安全的请求将重定向到keydove?

    选项2最接近Oauth工作组的建议,如果您有一个动态后端,那么它应该启动OIDC流,前端理想情况下不应该暴露于访问令牌,因为在公共客户端中很难安全。后端可以更安全地存储访问令牌,并在用户通过身份验证后向前端发送cookie。请询问您的答案,但如果我配置选项2,则所有请求都将重定向到keydove,include/api?所以,如果第三方想与我的系统集成,他们如何解析响应,因为所有请求都将重定向到登录页面?取决于第三方是谁,如果它是另一个系统,他们通常会使用不涉及浏览器的“客户端凭据”授权,这样他们就不会被重定向。您只需在KeyClope中为客户机凭据授权创建一个客户机,并向其提供客户机id和密码。然后,他们知道要访问您的api,他们首先使用id和secret调用keydape以获取访问令牌,然后使用令牌向您的api发出请求。因为它是通过后台频道直接呼叫,所以没有浏览器,所以不会重定向到任何内容。