diff --git a/django_saml2_auth/views.py b/django_saml2_auth/views.py index f72f0cd..4a9d827 100644 --- a/django_saml2_auth/views.py +++ b/django_saml2_auth/views.py @@ -112,7 +112,11 @@ def _create_new_user(username, email, firstname, lastname): user = User.objects.create_user(username, email) user.first_name = firstname user.last_name = lastname - user.groups = [Group.objects.get(name=x) for x in settings.SAML2_AUTH.get('NEW_USER_PROFILE', {}).get('USER_GROUPS', [])] + groups = [Group.objects.get(name=x) for x in settings.SAML2_AUTH.get('NEW_USER_PROFILE', {}).get('USER_GROUPS', [])] + if parse_version(get_version()) >= parse_version('2.0'): + user.groups.set(groups) + else: + user.groups = groups user.is_active = settings.SAML2_AUTH.get('NEW_USER_PROFILE', {}).get('ACTIVE_STATUS', True) user.is_staff = settings.SAML2_AUTH.get('NEW_USER_PROFILE', {}).get('STAFF_STATUS', True) user.is_superuser = settings.SAML2_AUTH.get('NEW_USER_PROFILE', {}).get('SUPERUSER_STATUS', False)