-
Notifications
You must be signed in to change notification settings - Fork 59
Two-Factor Authentication #2497
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
Merged
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f97ac17
Add 2FA, optional for users, required for staff
amickan 4692625
Add test for 2fa required for staff
amickan ad88711
Show userlinks on the set-up, delete and backup token pages, not on a…
amickan 13cea42
Fix tests
amickan 5c060e3
Add 2FA for social login
amickan c12cc3d
Add text code to mfa setup page
amickan 7a350fc
Merge main
amickan 3dbb664
Reinstall django-allauth-2fa
amickan 0db69bf
Merge branch 'main' into 2fa
amickan 7b5e849
Merge main
amickan 91e06b4
Update django-allauth-2fa
amickan 1408b42
Fix and reorder middleware
amickan e63201e
Add test for 2fa middleware
amickan f1f1d2e
Only show back-up tokens when generated
amickan 5ff21eb
Add back-up token explanation
amickan 2ea5d6a
Require 2FA token to remove 2FA authentication
amickan 5d430c1
Add tests for set-up and remove views
amickan 00f4d85
Merge main
amickan 7e63b3a
Reinstall django-allauth-2fa
amickan cafaf4f
Merge main
amickan 08eec0e
Re-install django-allauth-2fa
amickan 9500daa
Minor template changes
jmsmkn c454d4f
Merge remote-tracking branch 'origin/main' into 2fa
jmsmkn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| from allauth_2fa.middleware import BaseRequire2FAMiddleware | ||
| from django.urls import get_resolver | ||
| from django.utils.deprecation import MiddlewareMixin | ||
|
|
||
|
|
||
| class RequireStaffAndSuperuser2FAMiddleware(BaseRequire2FAMiddleware): | ||
| def require_2fa(self, request): | ||
| # Staff users and superusers are required to have 2FA. | ||
| return request.user.is_staff or request.user.is_superuser | ||
|
|
||
|
|
||
| class TwoFactorMiddleware(MiddlewareMixin): | ||
| """ | ||
| Reset the login flow if another page is loaded halfway through the login. | ||
| (I.e. if the user has logged in with a username/password, but not yet | ||
| entered their two-factor credentials.) This makes sure a user does not stay | ||
| half logged in by mistake. | ||
|
|
||
| """ | ||
|
|
||
| def process_request(self, request): | ||
| match = get_resolver(request.urlconf).resolve(request.path) | ||
| if not match.url_name or not match.url_name.startswith( | ||
| "two-factor-authenticate" | ||
| ): | ||
| try: | ||
| del request.session["allauth_2fa_user_id"] | ||
| except KeyError: | ||
| pass | ||
amickan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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
19 changes: 19 additions & 0 deletions
19
app/grandchallenge/profiles/templates/allauth_2fa/authenticate.html
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| {% extends "account/base.html" %} | ||
| {% load i18n %} | ||
|
|
||
| {% block content %} | ||
| <h1> | ||
| {% trans "Two-Factor Authentication" %} | ||
| </h1> | ||
| <p>{% trans "Enter the token from your authenticator app below." %}</p> | ||
| <form method="post" class="mt-3"> | ||
| {% csrf_token %} | ||
| {{ form.non_field_errors }} | ||
| {{ form.otp_token.label }}: | ||
| {{ form.otp_token }} | ||
| <br> | ||
| <button class="btn btn-primary mt-3" type="submit"> | ||
| {% trans 'Authenticate' %} | ||
| </button> | ||
| </form> | ||
| {% endblock %} |
53 changes: 53 additions & 0 deletions
53
app/grandchallenge/profiles/templates/allauth_2fa/backup_tokens.html
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| {% extends "base.html" %} | ||
| {% load i18n %} | ||
|
|
||
| {% block title %}Two-Factor Authentication{% endblock %} | ||
|
|
||
| {% block breadcrumbs %} | ||
| <ol class="breadcrumb"> | ||
| <li class="breadcrumb-item text-light">Users</li> | ||
| <li class="breadcrumb-item"><a | ||
| href="{% url 'profile-detail' username=request.user.username %}">{{ request.user.username }}</a></li> | ||
| <li class="breadcrumb-item active" aria-current="page">Two Factor Authentication Settings</li> | ||
| </ol> | ||
| {% endblock %} | ||
|
|
||
| {% block content %} | ||
| <h1 class="mb-3"> | ||
| {% trans "Two-Factor Authentication" %} | ||
| </h1> | ||
| <p><i class="fas fa-check-circle text-success mr-1"></i>{% trans 'Two-Factor Authentication is enabled for your account.' %}</p> | ||
|
|
||
| <h3 class="mt-4"> | ||
| {% trans "Back-Up Tokens" %} | ||
| </h3> | ||
| <p>{% trans "If you don't have your authentication device with you, you can access your account using backup tokens." %}</p> | ||
|
|
||
| {% if backup_tokens %} | ||
| {% if reveal_tokens %} | ||
| <ul> | ||
| {% for token in backup_tokens %} | ||
| <li>{{ token.token }}</li> | ||
| {% endfor %} | ||
| </ul> | ||
| {% else %} | ||
| {% trans 'Backup tokens have been generated, but are not revealed here for security reasons. Press the button below to generate new ones.' %} | ||
| {% endif %} | ||
| {% else %} | ||
| {% trans 'No tokens. Press the button below to generate some.' %} | ||
| {% endif %} | ||
|
|
||
| <form method="post"> | ||
| {% csrf_token %} | ||
| <button class="btn btn-primary" type="submit"> | ||
| {% trans 'Generate backup tokens' %} | ||
| </button> | ||
| </form> | ||
|
|
||
| <h3 class="mt-4"> | ||
| {% trans "Disable Two-Factor Authentication" %} | ||
| </h3> | ||
| <p>{% trans 'You can disable two-factor authentication for your account at any time.' %}</p> | ||
| <a class="btn btn-primary" href="{% url 'two-factor-remove' %}">Disable Two Factor Authentication</a> | ||
|
|
||
| {% endblock %} |
28 changes: 28 additions & 0 deletions
28
app/grandchallenge/profiles/templates/allauth_2fa/remove.html
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| {% extends "base.html" %} | ||
| {% load i18n %} | ||
|
|
||
| {% block title %}Disable Two-Factor Authentication{% endblock %} | ||
|
|
||
| {% block breadcrumbs %} | ||
| <ol class="breadcrumb"> | ||
| <li class="breadcrumb-item text-light">Users</li> | ||
| <li class="breadcrumb-item"><a | ||
| href="{% url 'profile-detail' username=request.user.username %}">{{ request.user.username }}</a></li> | ||
| <li class="breadcrumb-item active" aria-current="page">Disable Two Factor Authentication</li> | ||
| </ol> | ||
| {% endblock %} | ||
|
|
||
| {% block content %} | ||
| <h1> | ||
| {% trans "Disable Two-Factor Authentication" %} | ||
| </h1> | ||
|
|
||
| <p>{% trans "Are you sure you want to disable Two-Factor Authentication from your account?" %}</p> | ||
|
|
||
| <form method="post"> | ||
| {% csrf_token %} | ||
| <button class="btn btn-primary" type="submit"> | ||
| {% trans 'Yes, disable 2FA' %} | ||
| </button> | ||
| </form> | ||
| {% endblock %} |
47 changes: 47 additions & 0 deletions
47
app/grandchallenge/profiles/templates/allauth_2fa/setup.html
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| {% extends "base.html" %} | ||
| {% load i18n %} | ||
|
|
||
| {% block title %}Enable Two-Factor Authentication{% endblock %} | ||
|
|
||
| {% block breadcrumbs %} | ||
| <ol class="breadcrumb"> | ||
| <li class="breadcrumb-item text-light">Users</li> | ||
| <li class="breadcrumb-item"><a | ||
| href="{% url 'profile-detail' username=request.user.username %}">{{ request.user.username }}</a></li> | ||
| <li class="breadcrumb-item active" aria-current="page">Set-up Two Factor Authentication</li> | ||
| </ol> | ||
| {% endblock %} | ||
|
|
||
| {% block content %} | ||
| <h1> | ||
| {% trans "Setup Two-Factor Authentication" %} | ||
| </h1> | ||
|
|
||
| <h4> | ||
| {% trans 'Step 1' %}: | ||
| </h4> | ||
|
|
||
| <p> | ||
| {% trans 'Scan the QR code below with a token generator of your choice (e.g., Google Authenticator, Microsoft Authenticator).' %} | ||
| </p> | ||
|
|
||
| <img src="{{ qr_code_url }}" /> | ||
amickan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <h4> | ||
| {% trans 'Step 2' %}: | ||
| </h4> | ||
|
|
||
| <p> | ||
| {% trans 'Input the token generated by the app:' %} | ||
| </p> | ||
|
|
||
| <form method="post"> | ||
| {% csrf_token %} | ||
| {{ form.non_field_errors }} | ||
| {{ form.token.label }}: {{ form.token }} | ||
|
|
||
| <button class="btn btn-primary btn-sm" type="submit"> | ||
| {% trans 'Verify' %} | ||
| </button> | ||
| </form> | ||
| {% endblock %} | ||
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.