上一篇:【SpringBoot攻略十三、spring security oauth2服务端(password密码模式)】
基于上一篇做如下修改就OK了!
1、OAuth2AuthorizationServerConfig授权服务器
删除
// password模式需要authenticationManager
//endpoints.authenticationManager(authenticationManager)
添加
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
2、OAuth2ResourceServerConfig资源服务器
.antMatchers("/order/**").authenticated()
替换
.antMatchers("/order/**").hasRole("USER")
因为此时没有用户了
3、删除WebSecurityConfig
4、数据库添加一个grant_type等于client_credentials的用户
5、测试时可以按照上一篇的步骤
注意:client_credentials客户端模式没有refresh_token更新令牌!!!