客戶端:http://localhost:8080/spring-oauth-client/index.jsp
服務端:http://localhost:8080/spring-oauth-server/index.jsp
access_token=942090fc-1aa0-4444-8127-57214680df3b
驗證業務:http://localhost:8080/spring-oauth-server/m/dashboard?access_token=942090fc-1aa0-4444-8127-57214680df3b
一、客戶端環境搭建
1、客戶端工程導入和配置

2、客戶端工程發布和訪問
del /q D:\tools\Tomcat8.0\webapps\spring-oauth-client.war
del /q D:\tools\Tomcat8.0\webapps\spring-oauth-client
copy D:\workspace_SpringMybatis\spring-oauth-client\target\spring-oauth-client.war D:\tools\Tomcat8.0\webapps\spring-oauth-client.war
http://localhost:8080/spring-oauth-client/index.jsp
二、服務端環境搭建
1、本機數據庫安裝
2、服務端工程導入和配置

3、服務端發布和訪問
del /q D:\tools\Tomcat8.0\webapps\spring-oauth-server.war
del /q D:\tools\Tomcat8.0\webapps\spring-oauth-server
copy D:\workspace_SpringMybatis\spring-oauth-server\target\spring-oauth-server.war D:\tools\Tomcat8.0\webapps\spring-oauth-server.war
http://localhost:8080/spring-oauth-server/index.jsp
三、客戶端和服務端聯調
1、訪問客戶端
http://localhost:8080/spring-oauth-client/index.jsp

2、使用password模式申請access_token


得到access_token

3、找到目標業務和訪問形式
在服務端找到業務鏈接:http://localhost:8080/spring-oauth-server/m/dashboard?access_token=i_am_testing_access_token
注意請求受保護的資源時傳遞 Access Token 有兩種方式
- 方式一在URL參數中添加
access_token,即請求參數:<access_token,your_access_token> - 方式二在請求的Header中添加 Authorization, 其值為 beareryour_access_token, 即請求頭:<Authorization, beareryour_access_token>

4、攜帶access_token訪問業務
-
請求參數方式:
http://localhost:8080/spring-oauth-server/m/dashboard?access_token=942090fc-1aa0-4444-8127-57214680df3b
-
請求頭方式:
請求頭:Authorization=bearer942090fc-1aa0-4444-8127-57214680df3b
http://localhost:8080/spring-oauth-server/m/dashboard
返回業務結果如下:

四、訪問非授權url或token失效的情況
1、攜帶有效access_token
http://localhost:8080/spring-oauth-server/m/dashboard?access_token=8fc3782b-5e24-4816-80e6-879cb4d3f1cd

2、攜帶失效access_token
http://localhost:8080/spring-oauth-server/m/dashboard?access_token=942090fc-1aa0-4444-8127-57214680df3b

3、不攜帶access_token
http://localhost:8080/spring-oauth-server/m/dashboard
4、非授權url訪問
http://localhost:8080/spring-oauth-server/unity_user_info?access_token=8fc3782b-5e24-4816-80e6-879cb4d3f1cd


