gpt4 book ai didi

java - 带有表单登录的 Spring Security OAuth 2

转载 作者:行者123 更新时间:2023-11-29 03:03:35 24 4
gpt4 key购买 nike

我正在尝试将我的 Spring Boot 应用程序配置为使用表单登录,并使用 OAuth 2 授权服务器验证凭据(将凭据从表单登录发送到用户授权 URL。

但是,当我使用以下 SecurityConfig 并转到资源时,它没有使用表单登录,而是重定向到授权服务器,询问我的凭据(使用基本身份验证)和然后重定向回应用程序本身。

我正在使用以下 SecurityConfig:

@Configuration
@EnableOAuth2Sso
public class SecurityConfig extends OAuth2SsoConfigurerAdapter {

@Override
public void configure(HttpSecurity http) throws Exception {
http
.logout()
.and()
.antMatcher("/**")
.authorizeRequests()
.anyRequest().authenticated()
.and()
.csrf()
.csrfTokenRepository(csrfTokenRepository()).and()
.addFilterAfter(csrfHeaderFilter(), CsrfFilter.class)
.formLogin();
}

// CSRF repository + filter
}

我正在向 configure() 方法提供 formLogin(),但这似乎不起作用。

以下配置在我的application.yml文件中:

spring:
oauth2:
client:
clientId: test
clientSecret: secret
accessTokenUri: http://localhost:8081/uaa/oauth/token
userAuthorizationUri: http://localhost:8081/uaa/oauth/authorize
clientAuthenticationScheme: header
resource:
userInfoUri: http://localhost:8081/uaa/user

这个配置确实有效,因为在重定向之后我获得了授权,但它不是我希望它工作的方式(使用表单登录而不是重定向到 OAuth2 授权服务器)。

最佳答案

使用 SSO 的重点是用户通过 auth 服务器(在您的例子中为 localhost:8081)进行身份验证。如果你想要一个表单登录,那就是你需要实现它的地方,而不是在客户端应用程序中。

关于java - 带有表单登录的 Spring Security OAuth 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33386883/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com