feat(auth): 完成 AUTH-01~04 后端实现 - IP白名单中间件+mfa.py删除+agents.py重构+conftest修复
This commit is contained in:
@@ -18,7 +18,6 @@ from datetime import datetime
|
||||
from typing import Optional
|
||||
from uuid import UUID
|
||||
|
||||
import pyotp
|
||||
import qrcode
|
||||
import redis.asyncio as aioredis
|
||||
import bcrypt # P1 修复: 直接使用 bcrypt 库替代 passlib
|
||||
@@ -35,6 +34,7 @@ from app.dependencies import get_current_user, require_role, dep_wecom_service
|
||||
from app.models.agent import Agent
|
||||
from app.schemas.agent import AgentLogin, AgentResponse, AgentStatusUpdate
|
||||
from app.services.wecom_service import WecomService
|
||||
from app.services.mfa_service import MFAService
|
||||
from app.utils.response import AppException, ERR_UNAUTHORIZED, success_response
|
||||
from app.utils.error_codes import ErrorCode
|
||||
|
||||
@@ -282,9 +282,8 @@ async def agent_login(
|
||||
"role": agent.role, # 必须包含role字段,供前端校验权限
|
||||
})
|
||||
else:
|
||||
# 验证 OTP 码
|
||||
totp = pyotp.TOTP(agent.mfa_secret)
|
||||
if not totp.verify(body.otp_code, valid_window=1):
|
||||
# 验证 OTP 码(决策3:复用 MFAService 统一校验逻辑)
|
||||
if not MFAService.verify_code(agent.mfa_secret, body.otp_code, valid_window=1):
|
||||
raise AppException(1006, "OTP验证码错误,请重新输入")
|
||||
|
||||
# 3. 生成随机 token(使用统一格式)
|
||||
|
||||
Reference in New Issue
Block a user