Skip to content
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

Add 2 factor authentication to login #4657

Open
wants to merge 36 commits into
base: develop
Choose a base branch
from
Open

Conversation

perryr16
Copy link
Contributor

@perryr16 perryr16 commented May 3, 2024

Any background context you want to provide?

What's this PR do?

Uses an open source, well rated, free library django-two-factor-auth to add token authentication via any authenticator app (google authenticator, microsoft authenticator, etc...) or via email.

Users will only be prompted to enable 2FA on their first login following the introduction of this code. Opting in or out is at the user level and users can always access the 2FA settings from /profile > Two Factor.

If a user chooses "Token Generator" then a QR code is displayed and can be scanned by any number of auth apps. Once scanned, users can enter the token to login

If a user chooses "Email" then a token will be sent via email to the associated account.

The UI for this library uses Django templates and does not enter the angular layer. To customize the Django templates they have been imported into the seed/landing/templates/two_factor directory and edited. To make navigation changes to the response from django-2-f-a, the response must be caught in a custom django view (see /CustomLoginView.py)

How should this be manually tested?

  1. With token generator
    Login with any user > Enable 2Fa > Select "Token Generator "
    Scan QR code with auth app of choice and enter token
    User should be logged in

  2. With email
    Go to profile > Two Factor > disable two factor authentication
    then re-enable two factor and select "Email". An email will be sent out, if testing locally it will likely be found in the seed_web logs.
    Enter the token
    User should be logged in

Screenshot 2024-05-03 at 9 47 25 AM
  1. Disable 2fa
    Go to profile > two factor > disable two factor authentication
    log out
    log in
    user should be logged in without 2FA prompts.

What are the relevant tickets?

#4657

Screenshots (if appropriate)

@perryr16 perryr16 added the Feature Add this label to new features. This will be reflected in the change log when generated. label May 3, 2024
@perryr16 perryr16 marked this pull request as ready for review May 6, 2024 14:09
@perryr16 perryr16 requested a review from kflemin May 6, 2024 14:09
@kflemin
Copy link
Contributor

kflemin commented May 14, 2024

@perryr16, this is great! Documenting a few issues I ran into:

  1. first, when I choose the 'email' verification method, I see a whole lot of errors in the logs. A lot of these:
    "AttributeError": type object RequestContext has no attribute 'cancel_url', 'is_ali_root', 'ali_leaf', .... etc.

  2. I've also run into this error in the logs:
    raise VariableDoesNotExist("Failed lookup for key "
    django.template.base.VariableDoesNotExist: Failed lookup for key [method] in <EmailDevice: default (email@nrel.gov)>
    2024-05-14 15:23:51 DEBUG Exception while resolving variable 'method' in template 'two_factor/core/setup.html'.
    Traceback (most recent call last):
    File "/Users/kflemin/.pyenv/versions/seed-10/lib/python3.10/site-packages/django/template/base.py", line 829, in _resolve_lookup
    current = current[bit]
    TypeError: 'EmailDevice' object is not subscriptable

  3. On the login screens, there are 2 things that we need to change:

  • The first one is that we do not want to give them a "create my account" button.
  • The second one is that we have lost the 'forgot your password' functionality.

This is the old login screen:
Screenshot 2024-05-14 at 4 16 06 PM

And the new ones:

![Screenshot 2024-05-14 at 4 16 01 PM](https://github.com/SEED-platform/seed/assets/
Screenshot 2024-05-14 at 4 16 35 PM
2205659/b8ceb482-080c-4f43-8bd9-a201c7a4a75a)

Maybe if you just turn "Create my account" into "Forgot my password" it might be good enough?

thanks!

perryr16 and others added 10 commits May 16, 2024 14:34
* Speed up ali tree

* Fix Tests
* Automate ugprading a database from 12 to 14.

* parameterize source conversion and target test database service versions.

---------

Co-authored-by: Damon Haley <damon.haley@nrel.gov>
Added documentation for upgrading Postgres and TimescaleDB to the latest version
* Fix email

* Fix

* Fix

* Fix package.json

* map from property_view_id not id

---------

Co-authored-by: Katherine Fleming <2205659+kflemin@users.noreply.github.com>
Co-authored-by: Nicholas Long <1907354+nllong@users.noreply.github.com>
Co-authored-by: Nicholas Long <nicholas.long@nrel.gov>
* new stats table

* commitment sqft added to goal

* actions to  goal stats table

* stats table, actions dropdown

* stats, create goal_notes for newly uploaded properties

* add current cycle property ids to goal get

* actions dropdown and base for bulk goalnote edit

* bulk update goalnote

* bulk update historical note

* rename

* precommit

* permissions and tests

* lint

* permission refactor

* permission refactor

* lint

* phrasing

* small language update and added translations

---------

Co-authored-by: kflemin <2205659+kflemin@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Add this label to new features. This will be reflected in the change log when generated.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants