1 Star 0 Fork 0

张正强 / oauth2Demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

oauth2Demo

Spring Boot Oauth2-master

Oauth2支持的授权方式目前有5类

GRANT_TYPE Description
authorization_code 授权码模式(即先登录获取code,再获取token) [最常用]
password 密码模式(将用户名、密码传过去,直接获取token) [适用于移动设备]
client_credentials 客户端模式(无用户,用户向客户端注册,然后客户端以自己的名义向'服务端'获取资源)
implicit 简化模式(在redirect_uri的Hash传递token,客户端运行在浏览器中,如JS、Flash)
refresh_token 更新access_token

1. authorization_code

  • 申请code
http://localhost:8080/oauth/authorize?response_type=code&scope=read write&client_id=curl-client&redirect_uri=http://www.baidu.com&state=b375bc2b-25f7-4dce-9b36-5f9e2d20bda1
  • 登录
  • 是否允许
  • 返回code
http://www.baidu.com/?code=kG4F2N&state=b375bc2b-25f7-4dce-9b36-5f9e2d20bda1
  • 申请access_token
curl -X POST http://localhost:8080/oauth/token -H "Content-Type: application/x-www-form-urlencoded" -d "client_id=curl-client&client_secret=client-secret&grant_type=authorization_code&code=kG4F2N&redirect_uri=http://www.baidu.com"
  • 返回access_token
{"access_token":"30626e87-761f-410c-9497-84b29d310dd7","token_type":"bearer","refresh_token":"0843fbec-20e3-4802-93a0-357488403924","expires_in":29,"scope":"read write"}
  • 请求资源
curl http://localhost:8080/user/ping -H "Authorization: Bearer 30626e87-761f-410c-9497-84b29d310dd7"

2. password

  • 申请access_token
curl -X POST http://localhost:8080/oauth/token -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=password&scope=read%20write&client_id=curl-client&client_secret=client-secret&username=nangzi&password=nangzi"
  • 返回access_token
{"access_token":"9ac3fe0f-f380-4149-8fca-19a72374365d","token_type":"bearer","refresh_token":"0843fbec-20e3-4802-93a0-357488403924","expires_in":29,"scope":"read write"}
  • 请求资源
curl http://localhost:8080/user/ping -H "Authorization: Bearer 9ac3fe0f-f380-4149-8fca-19a72374365d"

空文件

简介

暂无描述 展开 收起
Java
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/qiang_zz/oauth2Demo.git
git@gitee.com:qiang_zz/oauth2Demo.git
qiang_zz
oauth2Demo
oauth2Demo
master

搜索帮助