服务器到服务器 OAuth2 Auth SpringBoot

问题描述

我正在使用 SpringBoot 2.3.4.RELEASE 并且我正在以各种方式实现 SSO 流程。我设法连接到自定义 OpenID 提供程序(由我们的客户构建)并返回到我的本地主机应用程序,其中包含客户提供的所有用户信息,包括令牌。

在流程“之间”有一个客户提供的表单登录页面..因此我想避免它作为最后一步。

我尝试在 SpringBoot 属性上使用 client_credential 配置如下:

spring.security.oauth2.client.provider.xxxx.issuer-uri=https://p2k-auth-xxxx/.net
spring.security.oauth2.client.provider.xxxx.authorization-uri=http://p2k-auth-proto/xxxx/connect/authorize
spring.security.oauth2.client.provider.xxxx.token-uri=https://p2k-auth-proto-xxxx/connect/token
spring.security.oauth2.client.registration.xxxx.client-id=client-id
spring.security.oauth2.client.registration.xxxx.client-secret=client-secret
spring.security.oauth2.client.registration.xxxx.redirect-uri=http://localhost:8080/callback
spring.security.oauth2.client.registration.xxxx.authorization-grant-type=client_credential
# spring.security.oauth2.client.registration.xxxx.client-authentication-method=post
spring.security.oauth2.client.registration.xxxx.scope=my-scope

在安全配置中,我只放了几行代码(处理其他情况):

@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

  @Override
  protected void configure(HttpSecurity http) throws Exception {
     http.authorizeRequests()
            .antMatchers("/").permitAll()                           
            .antMatchers("/protected/**").authenticated()
                                
            .and().logout().logoutSuccessUrl("http://localhost:8080/")
                                    
            .and().oauth2Login().redirectionEndpoint().baseUri("/callback*");
  }
}

我没有添加其他的,因为在前面的例子中,如果一个受保护的资源被调用,Spring 会自动重定向到正确的带有所需参数的 uri(client-id ecc..)。

在这种情况下,我得到以下错误

java.lang.IllegalArgumentException: Invalid Authorization Grant Type (client_credential) for Client Registration with Id:xxxx

我已经阅读了大量示例,但我无法使用 Spring Built in ClientRegistration

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)