出现这个问题的具体原因一般有以下两点:
1.在授权的部分我们一般是通过使用自己的login action进行http basic的方式进行授权,而我们在使用Spring Security的时候只对外暴露了登陆的这个接口,就是说其它的接口都在Spring Security的保护范围内了,包括/oauth的接口。
2.在通过1的post方式授权通过之后使用http://localhost:8090/oauth/token?client_id=1293380307393789953&client_secret=$2a101010IYtMMj4Rc0TIX6Ty4wy/POYIydxZt.fH/p8.rWWv.pPKyIw7tFt9i&grant_type=authorization_code&code=BIX1OXu69Z&redirect_uri=http://localhost:8090/index的方式进行授权,这样是可以的,但是在接下来通过post方式向/oauth/token这个接口获取access_token的时候,会发现这个时候authentication用的并不是前面授权通过的那个authentication,而是使用的匿名登陆的那个authentication,这样前面的authentication就无法正常使用,也会因此而得到Bad client credentials/401 authentication is required。
我们可以通过如下的方式解决这个问题 ,在AuthenticationServerCo