码迷,mamicode.com
首页 > 编程语言 > 详细

spring-oauth-server实践:客户端和服务端环境搭建

时间:2017-07-23 12:40:16      阅读:315      评论:0      收藏:0      [点我收藏+]

标签:cli   tar   word   业务   play   技术分享   dash   log   inf   

客户端: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

技术分享

技术分享 

spring-oauth-server实践:客户端和服务端环境搭建

标签:cli   tar   word   业务   play   技术分享   dash   log   inf   

原文地址:http://www.cnblogs.com/lexiaofei/p/7223928.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!