From 1a11b8622dfda1a02f9c423b49f44ac53317bc96 Mon Sep 17 00:00:00 2001 From: Mariano Ruiz Date: Mon, 2 Sep 2024 11:17:26 -0300 Subject: [PATCH] Google SSO enable/disable at runtime --- coleman/settings.py | 19 +++++++++++-------- coleman/urls.py | 16 ++++++++++------ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/coleman/settings.py b/coleman/settings.py index e776cb1..bdf6c5b 100644 --- a/coleman/settings.py +++ b/coleman/settings.py @@ -49,7 +49,6 @@ 'django.contrib.staticfiles', 'django_extensions', 'health_check', - 'django_google_sso', ] REST_ENABLED = env.bool('REST_ENABLED', False) @@ -178,14 +177,18 @@ } +# Google SSO (django-google-sso) GOOGLE_SSO_ENABLED = env.bool('GOOGLE_SSO_ENABLED', False) -SSO_SHOW_FORM_ON_ADMIN_PAGE = env.bool('SSO_SHOW_FORM_ON_ADMIN_PAGE', True) -GOOGLE_SSO_CLIENT_ID = env.str("GOOGLE_SSO_CLIENT_ID", None) -GOOGLE_SSO_CLIENT_SECRET = env.str('GOOGLE_SSO_CLIENT_SECRET', None) -GOOGLE_SSO_PROJECT_ID = env.str('GOOGLE_SSO_PROJECT_ID', "django-coleman") -GOOGLE_SSO_AUTO_CREATE_USERS = True -GOOGLE_SSO_STAFF_LIST = ["*"] -GOOGLE_SSO_ALLOWABLE_DOMAINS = env.str('GOOGLE_SSO_ALLOWABLE_DOMAINS', "gmail.com").split(',') +if GOOGLE_SSO_ENABLED: + SSO_SHOW_FORM_ON_ADMIN_PAGE = env.bool('SSO_SHOW_FORM_ON_ADMIN_PAGE', True) + GOOGLE_SSO_CLIENT_ID = env.str("GOOGLE_SSO_CLIENT_ID", None) + GOOGLE_SSO_CLIENT_SECRET = env.str('GOOGLE_SSO_CLIENT_SECRET', None) + GOOGLE_SSO_PROJECT_ID = env.str('GOOGLE_SSO_PROJECT_ID', "django-coleman") + GOOGLE_SSO_AUTO_CREATE_USERS = True + GOOGLE_SSO_STAFF_LIST = ["*"] + GOOGLE_SSO_ALLOWABLE_DOMAINS = env.str('GOOGLE_SSO_ALLOWABLE_DOMAINS', "gmail.com").split(',') + INSTALLED_APPS += ['django_google_sso'] + # # Custom configurations diff --git a/coleman/urls.py b/coleman/urls.py index 3aac851..0ead31a 100644 --- a/coleman/urls.py +++ b/coleman/urls.py @@ -29,12 +29,6 @@ urlpatterns = [ re_path('^api/v1/', include(router.urls)), re_path(r'^health/', include('health_check.urls')), - path( - "google_sso/", include( - "django_google_sso.urls", - namespace="django_google_sso" - ) - ), ] if settings.ADMIN: @@ -43,5 +37,15 @@ path('admin/', admin.site.urls), ] + urlpatterns +if settings.GOOGLE_SSO_ENABLED: + urlpatterns = [ + path( + "google_sso/", include( + "django_google_sso.urls", + namespace="django_google_sso" + ) + ), + ] + urlpatterns + admin.site.site_title = admin.site.site_header = settings.SITE_HEADER admin.site.index_title = settings.INDEX_TITLE