核心价值:
captcha库),并在敏感操作(如发短信、改密)前强制校验。后端:
captcha 库 (依赖 Pillow) - 生成原生图形验证码。BackgroundTasks (替代 APScheduler)。前端:
部署:
Users Table)id (Integer, PK)mobile (String(20), Unique, Index, Not Null)password_hash (String(128), Not Null), salt (Optional, if not using modern hashes that include salt)status (Enum: ACTIVE, DISABLED, Not Null, Default ACTIVE)created_at, updated_atApplications Table)id (Integer, PK)app_id (String(32), Unique, Index, Not Null) - 分配给第三方系统app_secret_hash (String(128), Not Null) - 用于接口签名access_token (String(64), Unique) - 永久有效的应用访问令牌,用于 M2M 接口鉴权。app_name, icon_urlprotocol_type (Enum: OIDC, SIMPLE_API)redirect_uris (Text, Not Null - JSON/Array), grant_types, response_types (Store in Hydra DB, but link via app_id)notification_url (String, Optional)created_at, updated_atAppUserMappings Table)id (Integer, PK)app_id (FK to Applications), user_id (FK to Users)mapped_key (String(100), Not Null) - 目标系统的账号(邮箱、用户名等)is_active (Boolean, Default True) - 映射关系是否启用。UNIQUE(app_id, user_id) 确保一个用户在同一应用下只映射一次。UNIQUE(app_id, mapped_key) (如果目标系统的账号在该应用内必须唯一)。/api/v1/auth/login): mobile, password, app_id (Optional for direct login). Returns JWT + refresh token./page/login (integrated into UAP)./auth/login endpoint, challenge param./page/pwd/reset (Handles SMS, validation, password update)./api/v1/open/sms/send, /api/v1/open/pwd/reset): Developers call these to implement their own UI.
sms/send: Requires captcha_id, captcha_code.pwd/reset: Requires mobile, sms_code, new_password, sign.captcha Python library + Pillow。/api/v1/utils/captcha):
GET: Generates captcha_id, image (Base64), stores code in Redis (key CAPTCHA:{uuid}, expiry settings.CAPTCHA_EXPIRE_SECONDS).POST /sms/send (and others) must call CaptchaService.verify_captcha(captcha_id, user_input) before proceeding.verify_captcha deletes the key upon success or first attempt (fail-safe).mapped_key 字段存储映射值。phone, mapped_key, name). Use pandas or openpyxl./api/v1/apps/{app_id}/mapping/preview):
pandas.mobile is not empty.Users table for existence.AppUserMappings table for duplicates.new, duplicate, invalid) and detailed rows with status, reason./api/v1/apps/{app_id}/mapping/import):
strategy (SKIP/OVERWRITE).INSERT IGNORE or ON DUPLICATE KEY UPDATE using SQLAlchemy./auth/login endpoint: Receives login_challenge from Hydra. Verifies user credentials (phone+pass) or checks UAP Session Cookie. Calls hydra.accept_login_request(challenge, subject=user_id)./auth/consent endpoint: Receives consent_challenge from Hydra. Fetches user's mappings for the client_id (App ID). Constructs id_token claims (e.g., email, preferred_username) based on mapped_key. Calls hydra.accept_consent_request(challenge, session={"id_token": {...}}).BackgroundTasks triggers send_webhook_notification.event_type (ADD, UPDATE, DISABLE), app_id, user_data (mobile, name, mapped_key, status).X-UAP-Signature must be verified by the receiving system.WebhookLogs table. Manual retry option for admins.POST /api/v1/apps/mapping/sync: 同步映射关系(新增/更新/停用)。支持 Header X-App-Access-Token。GET /api/v1/apps/{app_id}/users/query?mobile={mobile}: Returns user details and mappings. Used by legacy systems during login if local user not found.GET /api/v1/apps/{app_id}/users/changes?since={timestamp}: Returns a list of changes. Less critical if Webhook is primary.POST /api/v1/simple/ticket/exchange):
app_id (source), target_app_id, user_mobile, sign.app_id/sign. Looks up mapping for target_app_id and user_mobile. Generates a short-lived Ticket_B. Returns redirect_url (target_app_url/callback?ticket=TICKET_B).AUTH_SESSION_ID cookie, the redirection logic in /page/login (for SIMPLE_API apps) can directly generate Ticket_B without user interaction.tags=["Admin"] vs tags=["OpenAPI"], tags=["SimpleAuth"]./docs/admin (all routes) and /docs/open (filtered routes) using get_openapi and get_swagger_ui_html.Field descriptions, summary./docs/open into a Vue page using <iframe>. Provide separate guides for Signatures and Quick Start..env files, Docker secrets). Never hardcode./api/v1/open/ and /api/v1/simple/ endpoints must use HMAC-SHA256 signed requests with app_secret. Enforce signature validation.app_id and mobile.AUTH_SESSION_ID cookie, HTTPOnly, Secure flags. Handle logout by invalidating sessions.X-UAP-Signature on incoming webhook calls. Consider IP whitelisting for critical targets.app_secret) should grant only necessary permissions.代码生成:
调试与重构:
文档:
OIDC:
Depends injection for integrating with Ory Hydra SDK client."session data for accept_consent_request to include mapped email in id_token?"这份总结包含了你项目的核心架构、技术栈、数据库设计、API 规范、安全策略以及如何利用 Cursor AI 进行高效开发。祝你开发顺利!