在使用密码模式时,抛出异常:o.s.s.o.provider.endpoint.TokenEndpoint : Handling error: UnsupportedGrantTypeException, Unsupported grant type: password
解决方法:配置AuthenticationManager
@Configuration
@EnableAuthorizationServer
public class OAuth2AuthorizationServer extends AuthorizationServerConfigurerAdapter {
@Configuration
@EnableAuthorizationServer // 认证服务器
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
.....
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
// 设置令牌
endpoints.tokenStore(tokenStore());
endpoints.authenticationManager(authenticationManager); // 密码模式必须要配置这个
}
}
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
/**
* 需要配置这个支持password模式
* support password grant type
* @return
* @throws Exception
*/
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
}
原文链接:https://blog.csdn.net/hry2015/article/details/96380624