这个问题其实不是我们代码的问题,是我们请求方式的问题,或者说是请求工具的问题,这段时间在学习OAuth2.0协议框架SpringOAuth2.0,在搭建认证服务器之后请求完/oauth/authorize之后得到code后就会请求/oauth/token来得到access_token等相关信息

在得到code之后我就使用postMan发送/oauth/authorize请求,设置了请求头Content-Type:application/x-www-form-urlencoded

Authorization:Basic secret(secret是服务器端填写好的)

SpringOAuth2.0访问/oauth/token响应Invalid basic authentication token_spring


SpringOAuth2.0访问/oauth/token响应Invalid basic authentication token_谷歌浏览器_02


SpringOAuth2.0访问/oauth/token响应Invalid basic authentication token_谷歌浏览器_03


然后请求就报Invalid basic authentication token,感觉都没毛病呀!

这里请求参数获取地址​​OAuth2.0​

SpringOAuth2.0访问/oauth/token响应Invalid basic authentication token_spring_04


SpringOAuth2.0访问/oauth/token响应Invalid basic authentication token_请求参数_05


SpringOAuth2.0访问/oauth/token响应Invalid basic authentication token_spring_06


参数都正确,那么这时我换了一个接口测试工具,换了一个易文档的工具

SpringOAuth2.0访问/oauth/token响应Invalid basic authentication token_spring_07


为什么我要换测试工具呢,因为我怀疑是session的问题,还有浏览器认证信息缓存的问题,当然了,这只是我错误的猜想,就如上图还是返回失败,错误信息一样,然后我就找了一下相关资料

SpringOAuth2.0访问/oauth/token响应Invalid basic authentication token_spring_08


注意到这里需要base64加密,于是我就使用谷歌的Restlet Client插件测试,结果就可以了谷歌浏览器安装Restlet Client

SpringOAuth2.0访问/oauth/token响应Invalid basic authentication token_spring_09


关键点就再Authorization

SpringOAuth2.0访问/oauth/token响应Invalid basic authentication token_spring_10


SpringOAuth2.0访问/oauth/token响应Invalid basic authentication token_谷歌浏览器_11


其他参数保持不变,请求成功

SpringOAuth2.0访问/oauth/token响应Invalid basic authentication token_spring_12