[PR #22415] feat: implement multi-factor authentication (MFA) support #29924

Closed
opened 2026-02-21 20:46:30 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/22415

State: closed
Merged: No


This PR adds comprehensive MFA support to Dify, including:

  • Two-factor authentication using TOTP
  • Backup codes for account recovery
  • MFA management in user settings
  • Enhanced security for user accounts

Continuation of PR #22206 with improved implementation and tests.

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

This PR adds comprehensive MFA support to Dify, including:

  • Two-factor authentication using TOTP
  • Backup codes for account recovery
  • MFA management in user settings
  • Enhanced security for user accounts

Continuation of PR #22206 with improved implementation and tests.

Changes Made:

Backend (API) - New Files:

  • api/controllers/console/auth/mfa.py - MFA endpoints controller
  • api/services/mfa_service.py - Core MFA business logic
  • api/migrations/versions/2025_07_13_0900-xyz789abc123_add_account_mfa_settings.py - Database migration for MFA fields

Backend (API) - Modified Files:

  • api/controllers/console/auth/login.py - Added MFA verification step to login flow
  • api/controllers/console/__init__.py - Registered MFA blueprint
  • api/models/account.py - Added MFA-related fields (mfa_enabled, mfa_secret, mfa_backup_codes)
  • api/services/account_service.py - Extended with MFA support methods

Frontend (Web) - New Files:

  • web/app/components/header/account-setting/mfa-page.tsx - MFA management page
  • web/app/signin/components/mfa-verification.tsx - MFA verification component
  • web/service/use-mfa.ts - MFA service hook
  • web/i18n/*/mfa.ts - Internationalization files for 20 languages

Frontend (Web) - Modified Files:

  • web/app/components/header/account-setting/index.tsx - Added MFA settings navigation
  • web/app/signin/forms.tsx - Integrated MFA verification flow
  • web/service/common.ts - Added MFA API endpoints
  • web/i18n/*/index.ts - Imported MFA translations

Tests - New Files:

  • api/tests/unit_tests/services/test_mfa_service.py - Unit tests for MFA service
  • api/tests/unit_tests/controllers/console/auth/test_mfa*.py - Controller unit tests
  • api/tests/integration_tests/controllers/console/auth/test_mfa*.py - Integration tests
  • web/app/components/header/account-setting/mfa-page.test.tsx - React component tests
  • web/app/signin/components/mfa-verification.test.tsx - React component tests

Key Features:

  • TOTP-based two-factor authentication
  • Backup codes for account recovery (8 codes generated)
  • QR code generation for authenticator apps
  • Comprehensive error handling and validation
  • Full internationalization support (20 languages)
  • Secure storage of MFA secrets (encrypted)

Testing:

  • 15+ unit tests covering MFA service logic
  • Integration tests for all MFA endpoints
  • Frontend component tests
  • Manual testing completed on local environment

Screenshots

Screenshots will be added in the comments below

**Original Pull Request:** https://github.com/langgenius/dify/pull/22415 **State:** closed **Merged:** No --- This PR adds comprehensive MFA support to Dify, including: - Two-factor authentication using TOTP - Backup codes for account recovery - MFA management in user settings - Enhanced security for user accounts Continuation of PR #22206 with improved implementation and tests. > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 2. Ensure there is an associated issue and you have been assigned to it > 3. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary This PR adds comprehensive MFA support to Dify, including: - Two-factor authentication using TOTP - Backup codes for account recovery - MFA management in user settings - Enhanced security for user accounts Continuation of PR #22206 with improved implementation and tests. ### Changes Made: #### Backend (API) - New Files: - `api/controllers/console/auth/mfa.py` - MFA endpoints controller - `api/services/mfa_service.py` - Core MFA business logic - `api/migrations/versions/2025_07_13_0900-xyz789abc123_add_account_mfa_settings.py` - Database migration for MFA fields #### Backend (API) - Modified Files: - `api/controllers/console/auth/login.py` - Added MFA verification step to login flow - `api/controllers/console/__init__.py` - Registered MFA blueprint - `api/models/account.py` - Added MFA-related fields (mfa_enabled, mfa_secret, mfa_backup_codes) - `api/services/account_service.py` - Extended with MFA support methods #### Frontend (Web) - New Files: - `web/app/components/header/account-setting/mfa-page.tsx` - MFA management page - `web/app/signin/components/mfa-verification.tsx` - MFA verification component - `web/service/use-mfa.ts` - MFA service hook - `web/i18n/*/mfa.ts` - Internationalization files for 20 languages #### Frontend (Web) - Modified Files: - `web/app/components/header/account-setting/index.tsx` - Added MFA settings navigation - `web/app/signin/forms.tsx` - Integrated MFA verification flow - `web/service/common.ts` - Added MFA API endpoints - `web/i18n/*/index.ts` - Imported MFA translations #### Tests - New Files: - `api/tests/unit_tests/services/test_mfa_service.py` - Unit tests for MFA service - `api/tests/unit_tests/controllers/console/auth/test_mfa*.py` - Controller unit tests - `api/tests/integration_tests/controllers/console/auth/test_mfa*.py` - Integration tests - `web/app/components/header/account-setting/mfa-page.test.tsx` - React component tests - `web/app/signin/components/mfa-verification.test.tsx` - React component tests ### Key Features: - TOTP-based two-factor authentication - Backup codes for account recovery (8 codes generated) - QR code generation for authenticator apps - Comprehensive error handling and validation - Full internationalization support (20 languages) - Secure storage of MFA secrets (encrypted) ### Testing: - 15+ unit tests covering MFA service logic - Integration tests for all MFA endpoints - Frontend component tests - Manual testing completed on local environment ## Screenshots _Screenshots will be added in the comments below_
yindo added the pull-request label 2026-02-21 20:46:30 -05:00
yindo closed this issue 2026-02-21 20:46:30 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#29924