Springboot+Spring-Security+JWT+Redis实现restful Api的权限管理以及token管理
![](https://img2018.cnblogs.com/blog/1650518/201905/1650518-20190517083606453-678934576.png)
https://blog.csdn.net/lixiang987654321/article/details/83381494
OAuth 2.0定义了四种授权方式:
一.密码模式(resource owner password credentials)(为遗留系统设计)(支持refresh token)
- 这种模式是最不推荐的,因为client可能存了用户密码
- 这种模式主要用来做遗留项目升级为oauth2的适配方
- 当然如果client是自家的应用,也是可以
- 支持refresh token
- 使用client_id和client_secret以及用户名密码直接获取秘钥
- 请求地址: http://localhost:7010/uaa/oauth/token?grant_type=password&username=lixx&password=dw123456
二.授权码模式(authorization code)(正宗方式)(支持refresh token)
-
这种模式算是正宗的oauth2的授权模式
-
设计了auth code,通过这个code再获取token
-
支持refresh token
-
请求地址:http://localhost:7010/uaa/oauth/authorize?response_type=code&client_id=wx_takeout_client_id&redirect_uri=http://localhost:7010/uaa/login
三.简化模式(implicit)(为web浏览器应用设计)(不支持refresh token)
- 这种模式比授权码模式少了code环节,回调url直接携带token
- 这种模式的使用场景是基于浏览器的应用
- 这种模式基于安全性考虑,建议把token时效设置短一些
- 不支持refresh token
- implicit模式(隐式模式)和授权码模式(authorization_code)访问差不多,相比之下,少了一步获取code的步骤,而是直接获取token
-
请求: 用浏览器(此时同授权码模式,浏览器能跳转到登录页面,postman不行)
-
http://localhost:7010/uaa/oauth/authorize?response_type=token&client_id=wx_takeout_client_id&redirect_uri=http://localhost:7010/uaa/login
四.客户端模式(client credentials)(为后台api服务消费者设计)(不支持refresh token)
-
这种模式直接根据client的id和密钥即可获取token,无需用户参与
-
这种模式比较合适消费api的后端服务,比如拉取一组用户信息等
-
不支持refresh token,主要是没有必要
- 请求参数:请求头添加上 client_id和client_secret的basic编码,请求提添加grant_type必须设置为client_credentials
https://blog.csdn.net/WYA1993/article/details/85050120
springboot+springsecurity+oauth2整合(并用mysql数据库实现持久化客户端数据)
https://blog.csdn.net/Victor_An/article/details/81510874