uauth/readme.md

23 lines
1.1 KiB
Markdown
Raw Normal View History

2024-10-23 17:46:15 +08:00
# uauth
## run
- `go run . svc`
- `go run . client`
- `浏览器打开`[http://localhost:18080/login](http://localhost:18080/login)
## oauth2 authorization flow
- 1. 某某 系统/平台(比如: xx_platform) 的用户想要登录该 系统/平台, 并点击到登录页面
- 2. 用户发现该平台上有 `通过 {oauth2} 登录` 的按钮, 用户点击该按钮, 跳转到 `{oauth2}` 服务的登录页面如: `/oauth2/login`
> example: https://oauth2.com/login?client_id=...&scope=...&redirect_uri=...
> <b>需要注意, 这些参数都是必须的</b>
- 3. 跳转过来后, 有两种情况: 1. 用户没有在 {oauth2} 服务上登录过, 且当前的 token 依旧有效, 2. 用户在 {oauth2} 服务上未登录或者 token 已经过期
* 3.1 如果用户登录过且 token 有效, 则跳转到 `/oauth2/authorize` 进行授权
* 3.2 如果用户没有登录过, 或 token 已经失效, 则在登录成功后, 则跳转到 `/oauth2/authorize` 进行授权
- 4. 授权后, 会跳转到 redirect_uri 参数指定的地址, 并带上 code 和 state 参数
- 5. xx_platform 拿到 code 参数后, 向 {oauth2} 服务通过 code 请求 access_token