mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-21 11:43:56 +00:00
docs: sso oauth2.0 standard doc (#4612)
This commit is contained in:
@@ -296,24 +296,46 @@ fastgpt-sso:
|
||||
|
||||
### 标准 OAuth2.0
|
||||
|
||||
我们提供一套 RFC 6749 中鉴权码模式的 OAuth2.0 接入支持。
|
||||
参考:
|
||||
- [RFC 6749](https://datatracker.ietf.org/doc/html/rfc6749) 文档。
|
||||
- [阮一峰的网络日志](https://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html)
|
||||
|
||||
#### 参数需求
|
||||
|
||||
##### 三个地址
|
||||
我们提供一套标准的 OAuth2.0 接入流程。需要三个地址:
|
||||
|
||||
1. 登陆鉴权地址(登陆后将 code 传入 redirect_uri)
|
||||
- 需要将地址完整写好,除了 redirect_uri 以外(会自动补全)
|
||||
2. 获取 access_token 的地址,请求为 GET 方法,参数 code
|
||||
1. 登陆鉴权地址(用户点击 SSO 按钮后将携带参数直接跳转到该地址), 例如:`http://example.com/oauth/authorize`
|
||||
```bash
|
||||
curl -X GET\
|
||||
"http://example.com/oauth/authorize?response_type=code&client_id=s6BhdRkqt3&state=xyz&redirect_uri=https%3A%2F%2Ffastgpt.cn%2Flogin%2Fprovider"
|
||||
```
|
||||
用户输入账号密码后,会跳转到 redirect_uri 中,并携带 code 参数:
|
||||
`https://fastgpt.cn/login/provider?code=4/P7qD2qAz4&state=xyz`
|
||||
2. 获取 access_token 的地址,获取到 code 后,通过*服务器请求*该地址获取 access_token 例如:`http://example.com/oauth/access_token`
|
||||
```bash
|
||||
curl -X POST\
|
||||
-H "Content-Type: application/x-www-form-urlencoded"\
|
||||
"http://example.com/oauth/access_token?grant_type=authorization_code&client_id=s6BhdRkqt3&client_secret=xxx&code=4/P7qD2qAz4&redirect_uri=https%3A%2F%2Ffastgpt.cn%2Flogin%2Fprovider"
|
||||
```
|
||||
注意:Content-Type 必须是 application/x-www-form-urlencoded, 而不是 application/json
|
||||
3. 获取用户信息的地址,需要传入 access_token 例如:`http://example.com/oauth/user_info`
|
||||
```bash
|
||||
curl -X GET\
|
||||
-H "Authorization: Bearer 4/P7qD2qAz4"\
|
||||
"http://example.com/oauth/user_info"
|
||||
```
|
||||
注意: access_token 作为 Authorization 头部传入, 格式为 Bearer xxxx
|
||||
|
||||
```bash
|
||||
http://example.com/oauth/access_token?code=xxxx
|
||||
```
|
||||
##### 参数配置
|
||||
- CLIENT_ID: 必须
|
||||
- CLIENT_SECRET: 非必须,如果没有可以不配置
|
||||
- SCOPE: 非必须,如果没有可以不配置
|
||||
|
||||
3. 获取用户信息的地址
|
||||
|
||||
```bash
|
||||
http://example.com/oauth/user_info
|
||||
|
||||
```
|
||||
> redirect_uri 参数会根据运行环境自动补全
|
||||
>
|
||||
> 其他固定参数如 grant_type, response_type 等会自动补全
|
||||
|
||||
#### 配置示例
|
||||
|
||||
@@ -326,14 +348,21 @@ fastgpt-sso:
|
||||
- fastgpt
|
||||
environment:
|
||||
# OAuth2.0
|
||||
- AUTH_TOKEN=xxxxx
|
||||
- SSO_PROVIDER=oauth2
|
||||
# OAuth2 重定向地址
|
||||
# === 请求地址 ===
|
||||
# 1. OAuth2 登陆鉴权地址 (必填)
|
||||
- OAUTH2_AUTHORIZE_URL=
|
||||
# OAuth2 获取 AccessToken 地址
|
||||
# 2. OAuth2 获取 AccessToken 地址 (必填)
|
||||
- OAUTH2_TOKEN_URL=
|
||||
# OAuth2 获取用户信息地址
|
||||
# 3. OAuth2 获取用户信息地址 (必填)
|
||||
- OAUTH2_USER_INFO_URL=
|
||||
# === 参数 ===
|
||||
# 1. client_id (必填)
|
||||
- OAUTH2_CLIENT_ID=
|
||||
# 2. client_secret (选填,如果没有则不传)
|
||||
- OAUTH2_CLIENT_SECRET=
|
||||
# 3. scope (选填)
|
||||
- OAUTH2_SCOPE=
|
||||
# === 字段映射 ===
|
||||
# OAuth2 用户名字段映射(必填)
|
||||
- OAUTH2_USERNAME_MAP=
|
||||
# OAuth2 头像字段映射(选填)
|
||||
|
Reference in New Issue
Block a user