-
Notifications
You must be signed in to change notification settings - Fork 52
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
Two-Factor Authentication #2497
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2497 +/- ##
==========================================
+ Coverage 93.92% 94.00% +0.07%
==========================================
Files 814 816 +2
Lines 30069 30193 +124
==========================================
+ Hits 28243 28382 +139
+ Misses 1826 1811 -15
Continue to review full report at Codecov.
|
Wow... this looks pretty fan-ceee! |
re_path( | ||
r"accounts/two_factor/setup/?$", | ||
TwoFactorSetup.as_view(), | ||
name="two-factor-setup", | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to be a re_path
.
re_path( | |
r"accounts/two_factor/setup/?$", | |
TwoFactorSetup.as_view(), | |
name="two-factor-setup", | |
), | |
path( | |
"accounts/two_factor/setup/", | |
TwoFactorSetup.as_view(), | |
name="two-factor-setup", | |
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somehow the partial path turns out to be necessary. I'm not sure why, yet, but if I just use path it goes to the original setup view and not the custom one, even thought this url is defined before I include the allauth-2fa urls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice work!
This adds Two-Factor Authentication through the
django-allauth-2fa
package.I tested a few other packages, most notably
django_two_factor_auth
. It appears to be better maintained thandjango-allauth-2fa
, but there are some issues with it. Forcing 2fa for existing users that don't have a totp device set-up yet, for example, does not work - you get stuck in an infinite loop. This is a known issue, there is a workaround for it and also a PR to fix it, but this PR has been around for while and it's not clear when it will be incorporated. This and some other issues with integrating it made me decide to not use this package.I also checked out
django-mfa-2
, but that requires a lot of custom code to integrate.With
django-allauth-2fa
, any user of GC has the option to enable 2FA through a link in the profile:It works with the most common Authenticator apps and it also support backup tokens. Users can also remove 2FA again.
For staff users, 2FA is obligatory.
Getting this to work with social sign up required some custom code. The other packages also don't support 2FA with social sign up out of the box.
Back-up tokens:
At the moment, the backup tokens are always shown. That behaviour can be changed by setting
ALLAUTH_2FA_ALWAYS_REVEAL_BACKUP_TOKENS
to False in the settings.