From 4ae278d11999c2da2fafc7e49a9af676c583e033 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 31 Dec 2022 07:45:29 +1100 Subject: [PATCH] Fix for SOCIALACCOUNT_PROVIDERS (#4124) * Fix for SOCIALACCOUNT_PROVIDERS - Default (empty) setting should be dict, not list * Add extra examples to config template file * Add extra helper string * Re-implement brand icons for login screen --- InvenTree/InvenTree/settings.py | 6 +++++- InvenTree/config_template.yaml | 6 ++++-- InvenTree/templates/account/base.html | 12 ++++++++++++ InvenTree/templates/account/login.html | 6 +++--- .../socialaccount/snippets/provider_list.html | 9 +++++---- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index a9a9be4be0..ae3f5260e1 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -747,10 +747,14 @@ SITE_ID = 1 # Load the allauth social backends SOCIAL_BACKENDS = CONFIG.get('social_backends', []) + for app in SOCIAL_BACKENDS: INSTALLED_APPS.append(app) # pragma: no cover -SOCIALACCOUNT_PROVIDERS = CONFIG.get('social_providers', []) +SOCIALACCOUNT_PROVIDERS = CONFIG.get('social_providers', None) + +if SOCIALACCOUNT_PROVIDERS is None: + SOCIALACCOUNT_PROVIDERS = {} SOCIALACCOUNT_STORE_TOKENS = True diff --git a/InvenTree/config_template.yaml b/InvenTree/config_template.yaml index e42ab6a3fd..2659595381 100644 --- a/InvenTree/config_template.yaml +++ b/InvenTree/config_template.yaml @@ -194,11 +194,13 @@ remote_login_header: HTTP_REMOTE_USER # - 'django.middleware.clickjacking.XFrameOptionsMiddleware' # - 'InvenTree.middleware.AuthRequiredMiddleware' -# Add SSO login-backends +# Add SSO login-backends (see examples below) # social_backends: +# - 'allauth.socialaccount.providers.google' +# - 'allauth.socialaccount.providers.github' # - 'allauth.socialaccount.providers.keycloak' -# Add specific settings +# Add specific settings for social account providers (if required) # social_providers: # keycloak: # KEYCLOAK_URL: 'https://keycloak.custom/auth' diff --git a/InvenTree/templates/account/base.html b/InvenTree/templates/account/base.html index 518ab0798b..f71f2afcaf 100644 --- a/InvenTree/templates/account/base.html +++ b/InvenTree/templates/account/base.html @@ -101,6 +101,18 @@ $(document).ready(function () { showCachedAlerts(); + // Add brand icons for SSO providers, if available + $('.socialaccount_provider').each(function(i, obj) { + var el = $(this); + var tag = el.attr('brand_name'); + + var icon = window.FontAwesome.icon({prefix: 'fab', iconName: tag}); + + if (icon) { + el.append(` `); + } + }); + }); diff --git a/InvenTree/templates/account/login.html b/InvenTree/templates/account/login.html index 0572a4c4d8..08ece1b5d4 100644 --- a/InvenTree/templates/account/login.html +++ b/InvenTree/templates/account/login.html @@ -38,7 +38,7 @@ for a account and sign in below:{% endblocktrans %}

{% if login_message %}
{{ login_message | safe }}
{% endif %} -
+
@@ -49,8 +49,8 @@ for a account and sign in below:{% endblocktrans %}

{% if enable_sso %} -
-

{% trans 'or use SSO' %}

+
+{% trans "Sign in using third-party SSO" %}
{% include "socialaccount/snippets/provider_list.html" with process="login" %}
diff --git a/InvenTree/templates/socialaccount/snippets/provider_list.html b/InvenTree/templates/socialaccount/snippets/provider_list.html index d651bed0a6..dc24aa76e2 100644 --- a/InvenTree/templates/socialaccount/snippets/provider_list.html +++ b/InvenTree/templates/socialaccount/snippets/provider_list.html @@ -5,13 +5,14 @@ {% for provider in socialaccount_providers %} {% if provider.id == "openid" %} {% for brand in provider.get_brands %} - {{brand.name}} + href="{% provider_login_url provider.id openid=brand.openid_url process=process %}"> + {{brand.name}} {% endfor %} {% endif %} - {{provider.name}} {% endfor %}