Skip to content
Snippets Groups Projects
Verified Commit c5edd024 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Use setting for enabling username matching on social accounts

parent 0c50e68e
No related branches found
No related tags found
1 merge request!1487Allow matching social accounts to local accounts by their username
Pipeline #189178 passed with warnings
......@@ -335,19 +335,6 @@ class InviteCodePacketSize(IntegerPreference):
verbose_name = _("Size of packets. (Default 5: abcde)")
@site_preferences_registry.register
class SocialAccountUsernameMatchingEnabled(BooleanPreference):
section = auth
name = "social_account_username_matching_enabled"
default = False
verbose_name = _("Enable matching of third-party accounts to local accounts by username")
help_text = _(
"Warning: Only activate this option, if you are completely sure "
"that you want to match local accounts to third-party accounts "
"by their username and that the third-party provider can be trusted."
)
@site_preferences_registry.register
class OAuthAllowedGrants(MultipleChoicePreference):
"""Grant Flows allowed for OAuth applications."""
......
......@@ -327,6 +327,9 @@ if _SOCIALACCOUNT_PROVIDERS:
INSTALLED_APPS.append(f"allauth.socialaccount.providers.{provider}")
SOCIALACCOUNT_PROVIDERS[provider] = {k.upper(): v for k, v in config.items()}
ALEKSIS_SOCIALACCOUNT_USERNAME_MATCHING = _settings.get(
"auth.socialaccount_username_matching", False
)
# Configure custom forms
......
......@@ -29,11 +29,9 @@ class OurSocialAccountAdapter(DefaultSocialAccountAdapter):
"""Customised adapter that recognises other authentication mechanisms."""
def pre_social_login(self, request, sociallogin):
super().pre_social_login(request, sociallogin)
# Try to match social accounts to local accounts by their username if enabled
if (
get_site_preferences()["auth__social_account_username_matching_enabled"]
settings.ALEKSIS_SOCIALACCOUNT_USERNAME_MATCHING
and not sociallogin.is_existing
and sociallogin.account.extra_data.get("preferred_username")
):
......@@ -41,7 +39,7 @@ class OurSocialAccountAdapter(DefaultSocialAccountAdapter):
try:
user = get_user_model().objects.get(username=username)
sociallogin.user = user
logging.debug(f"Match local account {username} to social account")
logging.info(f"Match local account {username} to social account")
except get_user_model().DoesNotExist:
pass
......
......@@ -45,8 +45,10 @@ Match local accounts to social accounts by username
---------------------------------------------------
You can configure AlekSIS to automatically match local accounts to social accounts
by their username. To do this, enable the preference *Enable matching of third-party accounts to local accounts by username*
at *Admin → Configuration*.
by their username. To do this, set the following configuration::
[auth]
socialaccount_username_matching = true
.. warning::
Only activate this behavior, if you are completely sure
......
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