mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +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:
parent
3ba1d10fc4
commit
ba24ff570a
@ -1,5 +1,6 @@
|
|||||||
"""This module provides template tags pertaining to SSO functionality"""
|
"""This module provides template tags pertaining to SSO functionality"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
|
|
||||||
@ -7,6 +8,7 @@ from common.models import InvenTreeSetting
|
|||||||
from InvenTree.helpers import str2bool
|
from InvenTree.helpers import str2bool
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
logger = logging.getLogger('inventree')
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
@ -32,13 +34,23 @@ def sso_auto_enabled():
|
|||||||
def sso_check_provider(provider):
|
def sso_check_provider(provider):
|
||||||
"""Return True if the given provider is correctly configured"""
|
"""Return True if the given provider is correctly configured"""
|
||||||
|
|
||||||
|
import allauth.app_settings
|
||||||
from allauth.socialaccount.models import SocialApp
|
from allauth.socialaccount.models import SocialApp
|
||||||
|
|
||||||
# First, check that the provider is enabled
|
# 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
|
return False
|
||||||
|
|
||||||
# Next, check that the provider is correctly configured
|
# 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
|
# At this point, we assume that the provider is correctly configured
|
||||||
return True
|
return True
|
||||||
|
@ -78,6 +78,9 @@ Configure the social application entry with the app details:
|
|||||||
- Add the *site* which you want to provide access for this SSO app
|
- Add the *site* which you want to provide access for this SSO app
|
||||||
- Save the new application entry when configuration is finished
|
- Save the new application entry when configuration is finished
|
||||||
|
|
||||||
|
!!! warning "Site Selection"
|
||||||
|
You *must* assign the new application to at least one available site domain
|
||||||
|
|
||||||
!!! tip "Fix Your Mistakes"
|
!!! tip "Fix Your Mistakes"
|
||||||
You can always return to edit or adjust the social application details later
|
You can always return to edit or adjust the social application details later
|
||||||
|
|
||||||
@ -112,7 +115,7 @@ In the [settings screen](./global.md), navigate to the *Login Settings* panel. H
|
|||||||
|
|
||||||
### Configure Email
|
### Configure Email
|
||||||
|
|
||||||
Note that [email settings](./email.md) must be correctly configured before SSO will be activated. Ensure that your email setup is correctly configured and operataional.
|
Note that [email settings](./email.md) must be correctly configured before SSO will be activated. Ensure that your email setup is correctly configured and operational.
|
||||||
|
|
||||||
## Security Considerations
|
## Security Considerations
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user