Skip to content

添加二次认证支持#2

Open
Dustin-Jiang wants to merge 10 commits into
BIT101-dev:mainfrom
Dustin-Jiang:feat/mfa
Open

添加二次认证支持#2
Dustin-Jiang wants to merge 10 commits into
BIT101-dev:mainfrom
Dustin-Jiang:feat/mfa

Conversation

@Dustin-Jiang

@Dustin-Jiang Dustin-Jiang commented Jul 11, 2026

Copy link
Copy Markdown

全是GPT-5.6和GLM-5.2糊的

钉钉登录好像还不太能用,我这暂时测试不了了()短信验证码测试能用

SDK 二次认证

  • 新增可扩展的 SecondAuthFlowSecondAuthMethod 实现。
  • 支持短信验证码发送与验证。
  • 支持通过统一身份认证前端 API 创建、下载和轮询钉钉二维码。
  • 登录需要二次认证时抛出 second_auth_required,保留现有登录对象和 CAS Session。
  • 为 login、BaseLogin 及各服务登录类提供 MFA 兼容接口。
  • 支持 WebVPN 内部嵌套 MFA,并在验证完成后继续原服务回调流程。
  • 新增登录状态导出与恢复,保留 Cookie、Header、CAS execution 和服务回调状态。
  • 同步更新 bit_login/init.py 公共导出。

服务端无状态 MFA

  • 业务接口遇到 MFA 时返回 HTTP 428 和临时 challenge_token。
  • 新增以下接口:
    • POST /api/auth/second/sms/send
    • POST /api/auth/second/sms/verify
    • POST /api/auth/second/dingtalk/begin
    • POST /api/auth/second/dingtalk/poll
  • 使用 AES-GCM 加密并认证 MFA 状态,服务端无需保存待验证登录对象。
  • Challenge 绑定用户名、服务和过期时间,可跨 Worker 恢复。
  • 每次短信发送或钉钉轮询后签发包含最新状态的新 token。
  • MFA 成功后恢复原服务登录流程,并写入业务 Session 缓存。
  • 通过 MFA_METHODS 配置启用 sms、dingtalk 或两者;配置为空或包含未知方式时拒绝启动。

Add export_state/restore_state on login to serialize session cookies,
headers, and SecondAuthFlow state. Add export_second_auth_state/
restore_second_auth_state on BaseLogin to serialize the full service
login context including nested WebVPN MFA continuation.

Add initialize_network parameter to BaseLogin.__init__ to skip network
probe when restoring from a challenge token.
Split server/server.py into:
- server/core/: config, http timeout patch, SessionManager, auth
  orchestration, AES-GCM MFA challenge token module
- server/routers/: auth (MFA endpoints), jwb, jxzxehall, ics
- server/schemas.py: Pydantic request models

Add stateless MFA flow: business endpoints return HTTP 428 with an
encrypted challenge_token when second auth is required. Four new
endpoints handle SMS and DingTalk QR continuation without server-side
session state. MFA success writes the final session into the existing
SessionManager cache.

Fix /api/jwb/score using unimported jwb class and nonexistent
request.detailed field.
Aligns container runtime with .python-version.
Cover AES-GCM challenge token round-trip, tamper detection, expiry,
username binding; login session cookie/header/second-auth-state
round-trip; nested WebVPN MFA state restoration.
Document MFA_STATE_KEY/MFA_STATE_TTL environment variables, challenge
token flow, and four MFA endpoints. Update AGENTS.md to reflect MFA
architecture, uv workflow, and server runtime behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant