Spring mvc Spring/OAuth2错误-身份验证不足异常,没有客户端身份验证。尝试添加适当的身份验证筛选器
我花了几个小时试图弄清楚这个Spring Security OAuth2实现到底出了什么问题 当我点击Spring mvc Spring/OAuth2错误-身份验证不足异常,没有客户端身份验证。尝试添加适当的身份验证筛选器,spring-mvc,authentication,spring-security,oauth-2.0,spring-security-oauth2,Spring Mvc,Authentication,Spring Security,Oauth 2.0,Spring Security Oauth2,我花了几个小时试图弄清楚这个Spring Security OAuth2实现到底出了什么问题 当我点击/oauth/token端点时发生错误: 本地主机:8080/my oauth practice app/oauth/token 错误:身份验证不足异常,没有客户端身份验证。尝试添加适当的身份验证筛选器。 授权服务器配置 资源服务器配置 一般WEB安全配置 您应该像这样检查WebSecurity配置适配器方法: @Override public void configure(WebSecurit
/oauth/token
端点时发生错误:
本地主机:8080/my oauth practice app/oauth/token
错误:身份验证不足异常,没有客户端身份验证。尝试添加适当的身份验证筛选器。
授权服务器配置
资源服务器配置
一般WEB安全配置
您应该像这样检查WebSecurity配置适配器方法:
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/webjars/**", "/oauth/**");
}
删除“/oauth/**”路径。否则
TokenEndpoint.postAccessToken(Principal principal, @RequestParam Map<String, String> parameters)
TokenEndpoint.postAccessToken(主体,@RequestParam映射参数)
主体将为null。当主体为null时,可能意味着在到达方法之前未调用spring安全链。可以找到可能的修复方法
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Primary
@Bean
DefaultTokenServices tokenServices() {
DefaultTokenServices d = new DefaultTokenServices();
d.setAccessTokenValiditySeconds(600);
d.setRefreshTokenValiditySeconds(1000);
d.setTokenStore(new InMemoryTokenStore());
return d;
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("password").roles("USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/**").hasRole("USER");
}
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/webjars/**", "/oauth/**");
}
TokenEndpoint.postAccessToken(Principal principal, @RequestParam Map<String, String> parameters)