我试图将我的Spring Boot应用程序配置为使用表单登录,并使用OAuth 2授权服务器验证凭据(将凭据从表单登录发送到用户授权URL。
但是,当我使用以下内容SecurityConfig并转到资源时,而不是使用表单登录名,它会重定向到授权服务器,要求我提供凭据(使用基本身份验证),然后重定向回应用程序本身。
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 }
我提供了formLogin()该configure()方法,但这似乎不起作用。
formLogin()
configure()
我的application.yml文件中包含以下配置:
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)。如果要使用表单登录,则需要在此处实现它,而不是在客户端应用程序中。