繁体   English   中英

具有表单登录功能的Spring Security OAuth 2

[英]Spring Security OAuth 2 with form login

我试图将我的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)。 如果要使用表单登录,则需要在此处实现它,而不是在客户端应用程序中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM