【发布时间】:2021-05-20 13:50:46
【问题描述】:
现在我有了这个配置:
spring:
security:
oauth2:
client:
registration:
sbbol:
client-id: zdcffffff
client-secret: ffffffffff
scope:
- openid
client-authentication-method: post
authorization-grant-type: authorization_code
redirect-uri: '{baseUrl}/login/oauth2/code/{registrationId}'
client-authentication-scheme: form
provider:
sbbol:
authorization-uri: ${SBBOL_AUTH_URI}
token-uri: ${SBBOL_AUTH_URI}
user-info-uri: ${SBBOL_AUTH_URI}
user-name-attribute: sub
@Configuration
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic().disable();
http.cors().disable();
http.csrf().disable();
http.requestMatchers()
.antMatchers("/login", "/oauth2/authorization/sbbol", "/login/oauth2/code/sbbol")
.and()
.authorizeRequests().anyRequest().authenticated();
http.oauth2Login()
.defaultSuccessUrl("/user")
.permitAll();
}
}
这可行,但我的提供商要求我每 30 天通过一次休息 api 调用更改客户端密码。我有一个问题,如何在 Spring Security 中设置新的客户端密码?也许我可以将配置存储在数据库中?
【问题讨论】:
-
是的,您需要将这些详细信息保存在数据库中。您可以使用
oauth_client_details表和以下类似类型的列来保存详细信息,稍后您可以使用其余界面更改它。client_id, client_secret, scope, authorized_grant_types, web_server_redirect_uri, authorities, access_token_validity, refresh_token_validity, additional_information, autoapprove -
@harry 在我的情况下这完全可能吗?我认为这只有在 OAuth 2.0 服务器上才有可能。就我而言,我是客户。我正在尝试连接到与 Google 或 Okta 相同的 SSO 提供商
-
上述情况适用于当您的应用也充当 OAuth 提供者时,在同一服务或单独的独立服务器中运行 OAuth 服务器。由于您的提供商是第 3 方服务器,因此在这种情况下,正如您所提到的,他们正在公开一个端点来更改它,因此您需要使用自定义解决方案。
标签: java spring spring-boot spring-security