先来张图片
我在用psotman 测试oauth授权码模式的出现了401的异常, 就是调用oauth/token.
我是想用code换token,但是发现报错了。这是为什么呢? 首先你要理解
/oauth/token
- 这个如果配置支持allowFormAuthenticationForClients的,且url中有client_id和client_secret的会走ClientCredentialsTokenEndpointFilter来保护
- 如果没有支持allowFormAuthenticationForClients或者有支持但是url中没有client_id和client_secret的,走basic认证保护
所以我就明白怎么回事了
首先代码里面添加
@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
oauthServer
.tokenKeyAccess("permitAll()")
.checkTokenAccess("permitAll()")
.allowFormAuthenticationForClients();
// oauthServer.allowFormAuthenticationForClients();
}
然后再给postman 添加参数
这样就OK了