LetsMesh / Site

Repository for the Website named Let's Mesh
https://letsmesh.vercel.app
6 stars 2 forks source link

Leaf/b3.3 confirm 2 factor authentication #316

Closed gregoriusavip closed 3 months ago

gregoriusavip commented 8 months ago

Solving issue: #77

Features

Implementation

How It Should Work

  1. The user first will make a login request from the front end, filling in the required field of both email and password
  2. Upon clicking the login button, a post request to the login view from the backend is made
  3. Backend will verify if the request is valid, verifying if the user's data and password. If successful, backend will give both the accountID that ties to this user and the information if the user has 2FA enabled
  4. If 2FA is enabled, the page will be navigated to /otp where the user will be asked to input a 6 digit pin code, otherwise they will be directed to the logged_in_home page
  5. Simultaneously, a cookie holding the user's accountID will be created with a time limit. It will also call another post request to the backend, calling Set2FAView.
  6. Set2FAView will check if the user has 2FA enabled or not. If it doesn't then backend will generate a new seed and store it on the otp_base32 field for that user. Finally, backend will send an email to the corresponding user's email which holds the otp. NOTE Set2FAView might need a separate new view or function to handle the user's first-time setup, especially if MFA uses an authenticator to be implemented.
  7. Once the user input the 6 digit code and click the submit button, a post request is called for Verify2FAView, which take the cookie holding the user's accountID to find the correct OTP seed, and then verify if the 6 digit code is correct.
  8. Upon verification, the user will be redirected to the logged_in_home page.

Issues/Bugs/ToDos

Improvement

Note

While packages added to the project frontend are saved on package.json, I am not sure if that is also the case for the backend. Therefore to test the changes these packages needed to be installed:

django-cors-headers was used for testing calls made from front end to the back end. To do this, I run the front end using npm start and the backend using manage.py runserver. At the same time on django settings, both field, CORS_ORIGIN_WHITELIST and CORS_ALLOWED_ORIGINS are set as my localhost for the front end, which is "http://localhost:3000"

misslame commented 3 months ago

Good work!! Fix conflicts, and you should be good to go