-
Notifications
You must be signed in to change notification settings - Fork 8
added posman collection #1979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
maxto024
wants to merge
49
commits into
develop
Choose a base branch
from
mfa-review-documentation
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
added posman collection #1979
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Add POST /users/me/mfa/totp/initiate endpoint for MFA enrollment - Implement CRUD methods: update_pending_mfa, clear_pending_mfa, update_mfa_status - Add TOTPInitiateResponse domain model - Generate TOTP secret, encrypt, and store in pending_mfa_secret field - Return provisioning URI for QR code generation in authenticator apps - Requires JWT authentication via get_current_user dependency
- Add RecoveryCodeSchema with user_id FK, code_hash, code_encrypted, used, used_at fields - Add RecoveryCode internal and PublicRecoveryCode domain models - Add recovery_codes relationship and recovery_codes_generated_at to User model - Create Alembic migration for recovery_codes table with CASCADE delete - Add RecoveryCodeCRUD with create, get, mark_as_used, and delete operations - Migration verified: table, indexes, and constraints created successfully
- Add recovery code service with generation, hashing, and encryption utilities - Implement generate_recovery_codes() orchestration function - Add encryption configuration (MFA__RECOVERY_CODE_ENCRYPTION_KEY) - Create comprehensive integration tests (6 test cases) - Fix migration: Add migrated_date and migrated_updated columns Features: - Generate cryptographically secure recovery codes (XXXXX-XXXXX format) - Bcrypt hashing for verification security - Fernet encryption for display capability - Batch database insertion with transaction support - User timestamp tracking (recovery_codes_generated_at) Security: - 51.7 bits entropy (36^10 combinations) - Secrets module for cryptographic randomness - Defense-in-depth: hash for verification, encrypt for display - Bcrypt cost factor 12, Fernet AES-128 Tests: - End-to-end generation flow - Hash verification correctness - Encryption/decryption roundtrip - Code format validation (XXXXX-XXXXX) - Uniqueness guarantee - Default count parameter
- Step 3.1: Add recovery_codes field to TOTPVerifyResponse schema * Optional list[str] | None field with default=None * Backward compatible with existing clients - Step 3.2: Add conditional recovery code generation logic * Import generate_recovery_codes service * Check if first-time setup (recovery_codes_generated_at is None) * Generate 10 codes on first enrollment only * Return codes=None on re-enrollment - Step 3.4: Update endpoint documentation * Add docstring explaining recovery code behavior * Add OpenAPI summary and description * Document one-time display warning - Step 3.5: Add comprehensive integration tests * test_first_time_setup_generates_recovery_codes * test_recovery_codes_stored_in_database * test_user_timestamp_set_after_generation * test_reenrollment_no_codes_returned * test_invalid_code_no_recovery_codes * test_recovery_codes_format * All 6 tests passing Files modified: - src/apps/users/domain.py (schema) - src/apps/users/api/users.py (logic + docs) - src/apps/users/router.py (OpenAPI docs) - src/apps/users/tests/test_mfa_recovery_codes.py (new test file)
- Add GET /me/mfa/recovery-codes endpoint to view recovery codes with usage status - Add GET /me/mfa/recovery-codes/download endpoint to download codes as text file - Add RecoveryCodesListResponse and RecoveryCodeItemResponse domain objects - Add errors for MFA not enabled and codes not found - Add integration tests for both endpoints - Move recovery code generation logic to service layer - Update TOTP verify to use service for code generation
… generation failures
e6b6f82 to
7540ee3
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Do not merge
Pull request cannot be merged for some reason
documentation
Improvements or additions to documentation
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🔒 Multi-Factor Authentication (MFA) Implementation
Overview
This PR implements comprehensive Multi-Factor Authentication (MFA) for MindLogger using Time-based One-Time Password (TOTP) authentication. The implementation includes enrollment, login, recovery codes, and disable flows with enterprise-grade security features.
Branch:
mfa-review-documentationRelated PRs: #1973, #1976, #1977, #1978
✨ Features Implemented
1. TOTP-Based MFA (#1973)
2. Recovery Codes (#1976)
3. MFA Login Flow (#1977)
4. Security Features (#1978)
🧪 Testing Instructions
Prerequisites
docker compose up -dStep 1: Environment Setup
.envfile includes these MFA variables:Step 2: Using the Postman Collection
Import the Collection
MFA_Testing_Collection.postman_collection.jsonCollection Structure
The collection contains 7 test folders that should be run in order:
Running the Tests
Method 1: Run Entire Collection (Recommended)
Method 2: Run Individual Folders
Run each folder in sequence by clicking the "▶" next to each folder name.
What Each Test Folder Does
1️⃣ User Registration
test_email,test_password2️⃣ MFA Enrollment
totp_secret,access_token3️⃣ MFA Login with TOTP
4️⃣ Recovery Code Generation
5️⃣ Recovery Code Authentication
6️⃣ Rate Limiting Tests
7️⃣ MFA Disable Flow
Step 3: Verifying Results
In Postman Runner:
Key Success Indicators:
✅ Checklist for Reviewers
🔧 Minor Fixes Needed
users.py(lines 233-236)🚀 Ready for Production
The implementation is production-ready with the minor fixes above. All security features have been thoroughly tested and verified.
Questions? Check the detailed review documents or run the automated tests for hands-on verification.