-
Notifications
You must be signed in to change notification settings - Fork 56
Open
Labels
Description
Description
The application does not currently support enabling two-factor authentication (2FA) for users. Implement an endpoint to allow users to enable 2FA.
Acceptance Criteria
- Create an API endpoint:
POST /api/v1/auth/enable-2fa
- The endpoint should:
- Generate a 2FA secret key for the user.
- Generate a QR code for authentication apps like Google Authenticator.
- Store the 2FA secret securely in the database.
- Require the user to verify 2FA setup by providing a valid one-time passcode (OTP).
- Enable 2FA for the user upon successful verification.
Responses
✅ Success Response (200 OK)
{ "message": "2FA enabled successfully" }
📌 QR Code Response (200 OK - initial request before verification)
{ "message": "Scan the QR code to set up 2FA", "qr_code": "data:image/png;base64,....", "secret": "JBSWY3DPEHPK3PXP" }
❌ Error Responses
- Invalid OTP (400 Bad Request)
{ "error": "Invalid OTP. Please try again." }
- 2FA Already Enabled (409 Conflict)
{ "error": "2FA is already enabled for this account." }
- Unauthorized Request (401 Unauthorized)
{ "error": "User not authenticated" }
Technical Notes
- Use
Time-based One-Time Password (TOTP)
for 2FA. - Ensure proper error handling for invalid OTPs and edge cases.
- Follow the existing authentication structure in the project.