- 从服务器拉取完整代码 - 按框架规范整理项目结构 - 配置 Drone CI 测试环境部署 - 包含后端(FastAPI)、前端(Vue3)、管理端 技术栈: Vue3 + TypeScript + FastAPI + MySQL
94 lines
2.4 KiB
Markdown
94 lines
2.4 KiB
Markdown
# Agent-Auth 依赖关系
|
||
|
||
## 依赖概览
|
||
Agent-Auth是基础模块,**不依赖其他业务模块**,但依赖系统基础设施。
|
||
|
||
## 输入依赖
|
||
|
||
### 1. 系统基础设施
|
||
- `app/config/settings.py` - 系统配置
|
||
- `app/config/database.py` - 数据库连接
|
||
- `app/core/logger.py` - 日志系统
|
||
- `app/models/base.py` - 基础模型类
|
||
- `app/schemas/base.py` - 基础Schema类
|
||
|
||
### 2. 第三方库
|
||
- `fastapi` - Web框架
|
||
- `sqlalchemy` - ORM
|
||
- `passlib[bcrypt]` - 密码加密
|
||
- `python-jose[cryptography]` - JWT处理
|
||
- `redis` - 缓存(用于Token黑名单)
|
||
|
||
### 3. 环境变量
|
||
```bash
|
||
SECRET_KEY=必需
|
||
ALGORITHM=可选(默认HS256)
|
||
ACCESS_TOKEN_EXPIRE_MINUTES=可选(默认30)
|
||
REFRESH_TOKEN_EXPIRE_DAYS=可选(默认7)
|
||
```
|
||
|
||
## 输出接口
|
||
|
||
### 1. 依赖注入函数
|
||
其他所有模块都会使用这些函数:
|
||
```python
|
||
# app/api/deps.py 或 app/core/deps.py
|
||
async def get_current_user() -> User
|
||
async def get_current_active_user() -> User
|
||
async def get_optional_current_user() -> Optional[User]
|
||
|
||
# 角色检查器
|
||
require_admin = RoleChecker(["admin"])
|
||
require_manager = RoleChecker(["admin", "manager"])
|
||
require_trainer = RoleChecker(["admin", "manager", "trainer"])
|
||
```
|
||
|
||
### 2. 安全工具函数
|
||
```python
|
||
# app/core/security.py
|
||
def verify_password(plain_password: str, hashed_password: str) -> bool
|
||
def get_password_hash(password: str) -> str
|
||
def create_access_token(subject: int, **kwargs) -> str
|
||
def create_refresh_token(subject: int) -> str
|
||
def verify_token(token: str) -> dict
|
||
```
|
||
|
||
### 3. 数据模型
|
||
```python
|
||
# app/models/user.py
|
||
class User(BaseModel, AuditMixin):
|
||
# 被所有其他模块引用的用户模型
|
||
pass
|
||
```
|
||
|
||
### 4. API端点
|
||
```
|
||
POST /api/v1/auth/login
|
||
POST /api/v1/auth/register
|
||
POST /api/v1/auth/logout
|
||
POST /api/v1/auth/refresh
|
||
POST /api/v1/auth/reset-password
|
||
```
|
||
|
||
## 被依赖情况
|
||
|
||
以下模块依赖Auth模块:
|
||
- **所有模块** - 使用认证和权限检查
|
||
- Agent-User - 使用User模型
|
||
- Agent-Course - 使用get_current_user
|
||
- Agent-Exam - 使用get_current_user
|
||
- Agent-Training - 使用get_current_user
|
||
- Agent-Analytics - 使用权限检查
|
||
- Agent-Admin - 使用require_admin
|
||
|
||
## 接口稳定性
|
||
⚠️ **关键接口,需保持稳定**
|
||
- 修改认证逻辑会影响所有模块
|
||
- Token格式变更需要通知所有模块
|
||
- User模型字段变更需要评估影响
|
||
|
||
## 测试依赖
|
||
- 需要模拟Redis服务
|
||
- 需要测试数据库
|
||
- 需要模拟邮件服务(密码重置)
|