mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 12:35:46 +00:00
SSO bug fix (#4972)
* Catch SSO error - If social application is not assigned to at least one site, errors happen - Check if at least one site is enabled * Docs updates * Typo fix
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
"""This module provides template tags pertaining to SSO functionality"""
|
||||
|
||||
import logging
|
||||
|
||||
from django import template
|
||||
|
||||
@ -7,6 +8,7 @@ from common.models import InvenTreeSetting
|
||||
from InvenTree.helpers import str2bool
|
||||
|
||||
register = template.Library()
|
||||
logger = logging.getLogger('inventree')
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
@ -32,13 +34,23 @@ def sso_auto_enabled():
|
||||
def sso_check_provider(provider):
|
||||
"""Return True if the given provider is correctly configured"""
|
||||
|
||||
import allauth.app_settings
|
||||
from allauth.socialaccount.models import SocialApp
|
||||
|
||||
# First, check that the provider is enabled
|
||||
if not SocialApp.objects.filter(provider__iexact=provider.name).exists():
|
||||
apps = SocialApp.objects.filter(provider__iexact=provider.name)
|
||||
|
||||
if not apps.exists():
|
||||
return False
|
||||
|
||||
# Next, check that the provider is correctly configured
|
||||
app = apps.first()
|
||||
|
||||
if allauth.app_settings.SITES_ENABLED:
|
||||
# At least one matching site must be specified
|
||||
if not app.sites.exists():
|
||||
logger.error(f"SocialApp {app} has no sites configured")
|
||||
return False
|
||||
|
||||
# At this point, we assume that the provider is correctly configured
|
||||
return True
|
||||
|
Reference in New Issue
Block a user