Files
012-kaopeilian/docs/规划/全链路联调/言迹智能工牌/授权认证.md
111 998211c483 feat: 初始化考培练系统项目
- 从服务器拉取完整代码
- 按框架规范整理项目结构
- 配置 Drone CI 测试环境部署
- 包含后端(FastAPI)、前端(Vue3)、管理端

技术栈: Vue3 + TypeScript + FastAPI + MySQL
2026-01-24 19:33:28 +08:00

69 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 授权认证
## 概述
言迹开放平台采用标准OAuth2.0客户端授权认证模式。
## 认证方式
Header传递`Authorization: Bearer {access_token}`
## 获取access_token
### 请求信息
- **请求方式**GETHTTPS测试环境可使用HTTP
- **请求地址**`/oauth/token`
### 请求参数Query
| 参数 | 是否必填 | 类型 | 说明 |
|------|---------|------|------|
| grant_type | 是 | string | 授权类型,固定值:`client_credentials` |
| client_id | 是 | string | 客户端ID由言迹分配提供 |
| client_secret | 是 | string | 客户端密钥(由言迹分配提供) |
### 请求示例
```bash
curl --location --request GET 'https://open-test.yanjiai.com/oauth/token?grant_type=client_credentials&client_id=1Fld4LCWt2vpJNG5&client_secret=XE8w413qNtJBOdWc2aCezV0yMIHpUuTZ'
```
### 响应结果
```json
{
"access_token": "c5a3ad54-4622-4588-a490-5116407f602b",
"token_type": "bearer",
"expires_in": 3600,
"scope": "read write"
}
```
### 响应字段说明
| 字段 | 类型 | 说明 |
|------|------|------|
| access_token | string | 访问令牌 |
| token_type | string | 令牌类型,固定为"bearer" |
| expires_in | integer | 过期时间(秒) |
| scope | string | 权限范围 |
## 使用示例
获取token后在后续请求中携带
```bash
curl --location --request GET 'https://open-test.yanjiai.com/api/saas/user' \
--header 'Authorization: Bearer c5a3ad54-4622-4588-a490-5116407f602b'
```
## 注意事项
1. **Token缓存**access_token有效期为1小时建议缓存复用
2. **过期处理**token过期后需重新获取
3. **安全存储**client_secret需要安全存储不要暴露在前端
4. **并发控制**:避免频繁调用认证接口