spring-boot-starter-oauth2-client 未将 client_id 发送到外部 SSO

问题描述 投票:0回答:1

我正在使用

spring-security-starter-oauth2-client
尝试配置 Spring Boot 应用程序以使用我公司的 PingFederate SSO 页面,该页面托管在与该应用程序不同的域中。根据我当前的配置,未经授权的用户将被转发到 SSO 页面,但 URL 中没有传递任何必要的参数(例如 client_id),因此失败。

application.yaml

spring:
  mvc.servlet.path: /my-app/
  security:
    oauth2:
      client:
        registration:
          pingfed:
            authorization-grant-type: authorization_code
            client-id: foo
            client-secret: bar
            scope: openid, profile, email
        provider:
          pingfed:
            authorization-uri: https://sso.company.com/as/authorization.oauth2
            issuer-uri: https://sso.company.com
            token-uri: https://sso.company.com/as/token.oauth2
            user-info-uri: https://sso.company.com/idp/userinfo.openid
            jwk-set-uri: https://sso.company.com/pf/JWKS

Oauth2Config.java

@Configuration
public class OAuth2ClientConfig {
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .anyRequest().authenticated()
                .and()
                .oauth2Login();
        return http.build();
    }
}

当我运行应用程序并点击受保护的页面时,它会将我转发到登录页面https://sso.company.com/as/authorization.oauth2,我收到“client_id not found”类型错误。

当我从工作(非 Spring)应用程序中点击此 SSO 时,该 url 包含预期的参数: https://sso.company.com/as/authorization.oauth2?client_id=foo&code_chanllenge=xyz&scope=openid&etc

我错过了什么?有没有办法更改登录网址而无需手动添加所有参数?

更新
我通过注释掉我的“mvc.servlet.path”设法让它按预期工作。我相信这是 Spring 将默认登录放在 http://localhost:8080/oauth2/authorization/pingfed 的问题,而我的应用程序在 http://localhost:8080/my-app/ 运行,但我不是确定如何配置它。

spring-boot spring-mvc spring-oauth2 pingfederate spring-boot-starter-oauth2-client
1个回答
0
投票

不知道我是如何错过这一点的,但答案是更改

authorizationEndpoint.baseUri
配置中的
SecurityFilterChain
以在默认登录之前包含 mvc servlet 路径。 (Spring 会自动将“registrationId”添加到路径末尾。)

@Configuration
public class OAuth2ClientConfig {
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .anyRequest().authenticated()
                .and()
                .oauth2Login()
                    .authorizationEndpoint()
                        .baseUri("/my-app/oauth2/authorization")
        return http.build();
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.