Skip to content
Snippets Groups Projects
Verified Commit ec7488d2 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Make 2FA completely optional.

parent 37665310
No related branches found
No related tags found
1 merge request!59Resolve "2FA"
...@@ -67,10 +67,6 @@ INSTALLED_APPS = [ ...@@ -67,10 +67,6 @@ INSTALLED_APPS = [
'django_select2', 'django_select2',
'hattori', 'hattori',
'biscuit.core', 'biscuit.core',
'django_otp',
'django_otp.plugins.otp_static',
'django_otp.plugins.otp_totp',
'two_factor',
'impersonate', 'impersonate',
] ]
...@@ -103,7 +99,6 @@ MIDDLEWARE = [ ...@@ -103,7 +99,6 @@ MIDDLEWARE = [
'impersonate.middleware.ImpersonateMiddleware', 'impersonate.middleware.ImpersonateMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django_otp.middleware.OTPMiddleware',
'easyaudit.middleware.easyaudit.EasyAuditMiddleware', 'easyaudit.middleware.easyaudit.EasyAuditMiddleware',
'maintenance_mode.middleware.MaintenanceModeMiddleware', 'maintenance_mode.middleware.MaintenanceModeMiddleware',
# 'django.middleware.cache.FetchFromCacheMiddleware' # 'django.middleware.cache.FetchFromCacheMiddleware'
...@@ -323,15 +318,24 @@ CRON_CLASSES = [ ...@@ -323,15 +318,24 @@ CRON_CLASSES = [
ANONYMIZE_ENABLED = _settings.get('maintenance.anonymisable', True) ANONYMIZE_ENABLED = _settings.get('maintenance.anonymisable', True)
if _settings.get('2fa.yubikey.enabled', False): if _settings.get('2fa.enabled', False):
INSTALLED_APPS.insert(INSTALLED_APPS.index('two_factor')+1, 'otp_yubikey') for app in ['two_factor', 'django_otp.plugins.otp_totp', 'django_otp.plugins.otp_static', 'django_otp']:
INSTALLED_APPS.insert(INSTALLED_APPS.index('biscuit.core')+1, app)
MIDDLEWARE.insert(MIDDLEWARE.index('django.contrib.auth.middleware.AuthenticationMiddleware')+1, 'django_otp.middleware.OTPMiddleware')
if _settings.get('2fa.twilio.sid', None): if _settings.get('2fa.yubikey.enabled', False):
MIDDLEWARE.insert(MIDDLEWARE.index('django_otp.middleware.OTPMiddleware')+1, 'two_factor.middleware.threadlocals.ThreadLocals') INSTALLED_APPS.insert(INSTALLED_APPS.index('two_factor')+1, 'otp_yubikey')
TWILIO_SID = _settings.get('2fa.twilio.sid')
TWILIO_TOKEN = _settings.get('2fa.twilio.token') if _settings.get('2fa.call.enabled', False):
TWILIO_CALLER_ID = _settings.get('2fa.twilio.callerid') TWO_FACTOR_CALL_GATEWAY = 'two_factor.gateways.twilio.gateway.Twilio'
TWO_FACTOR_CALL_GATEWAY = 'two_factor.gateways.twilio.gateway.Twilio'
TWO_FACTOR_SMS_GATEWAY = 'two_factor.gateways.twilio.gateway.Twilio' if _settings.get('2fa.sms.enabled', False):
TWO_FACTOR_SMS_GATEWAY = 'two_factor.gateways.twilio.gateway.Twilio'
if _settings.get('2fa.twilio.sid', None):
MIDDLEWARE.insert(MIDDLEWARE.index('django_otp.middleware.OTPMiddleware')+1, 'two_factor.middleware.threadlocals.ThreadLocals')
TWILIO_SID = _settings.get('2fa.twilio.sid')
TWILIO_TOKEN = _settings.get('2fa.twilio.token')
TWILIO_CALLER_ID = _settings.get('2fa.twilio.callerid')
_settings.populate_obj(sys.modules[__name__]) _settings.populate_obj(sys.modules[__name__])
...@@ -3,8 +3,6 @@ from django.conf import settings ...@@ -3,8 +3,6 @@ from django.conf import settings
from django.conf.urls.static import static from django.conf.urls.static import static
from django.urls import include, path from django.urls import include, path
from two_factor.urls import urlpatterns as tf_urls
import debug_toolbar import debug_toolbar
from . import views from . import views
...@@ -34,11 +32,13 @@ urlpatterns = [ ...@@ -34,11 +32,13 @@ urlpatterns = [
path('contact/', include('contact_form.urls')), path('contact/', include('contact_form.urls')),
path('impersonate/', include('impersonate.urls')), path('impersonate/', include('impersonate.urls')),
path('__i18n__/', include('django.conf.urls.i18n')), path('__i18n__/', include('django.conf.urls.i18n')),
path('select2/', include('django_select2.urls')), path('select2/', include('django_select2.urls'))
path('', include(tf_urls))
] ]
# Add URLs for optional features # Add URLs for optional features
if 'two_factor' in settings.INSTALLED_APPS:
from two_factor.urls import urlpatterns as tf_urls # noqa
urlpatterns += [path('', include(tf_urls))]
if hasattr(settings, 'TWILIO_ACCOUNT_SID'): if hasattr(settings, 'TWILIO_ACCOUNT_SID'):
from two_factor.gateways.twilio.urls import urlpatterns as tf_twilio_urls # noqa from two_factor.gateways.twilio.urls import urlpatterns as tf_twilio_urls # noqa
urlpatterns += [path('', include(tf_twilio_urls))] urlpatterns += [path('', include(tf_twilio_urls))]
......
...@@ -50,14 +50,15 @@ django-hattori = "^0.2" ...@@ -50,14 +50,15 @@ django-hattori = "^0.2"
psycopg2 = "^2.8" psycopg2 = "^2.8"
django_select2 = "^7.1" django_select2 = "^7.1"
requests = "^2.22" requests = "^2.22"
django-otp = "^0.7.4"
django-formtools = "^2.1" django-formtools = "^2.1"
django-two-factor-auth = "^1.9" django-otp = { version = "^0.7.4", optional = true }
django-two-factor-auth = { version = "^1.9", optional = true }
django-otp-yubikey = { version = '^0.5.2', optional = true } django-otp-yubikey = { version = '^0.5.2', optional = true }
twilio = { version = "^6.33", optional = true } twilio = { version = "^6.33", optional = true }
[tool.poetry.extras] [tool.poetry.extras]
ldap = ["django-auth-ldap"] ldap = ["django-auth-ldap"]
2fa = ["django-otp", "django-two-factor-auth"]
twilio = ["twilio"] twilio = ["twilio"]
yubikey = ["django-otp-yubikey"] yubikey = ["django-otp-yubikey"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment