Reputation: 96
I've spent the past 4 hours looking through so many resources trying everything to solve this and nothing with success. The short is that I'm trying to add a default group to all new users created. Users are created the first time they authenticate via AAD/SSO, but when they come in, they have no Auths. I'd like to have them receive a default group when the SSO process creates the user (e.g. from the post-save receiver of the User object). I've looked through dozens of examples using something very similar to the below code. OK fine, the process runs, never generates any errors, and successfully creates the CustomUserProfile record, but the user never gets assigned the default group. 110% chance the group exists and the get finds the group (have done exercises to confirm this).
What do I have wrong on this?? Why won't this process create the group assignment (or hit the error process to tell me what's going on here)?
using django 3.2.8, Python 3.8.7
@receiver(post_save, sender=User)
def create_profile(sender, instance, created, **kwargs):
try:
if created:
instance.groups.add(Group.objects.get(name='Basis - Standard Access'))
CustomUserProfile.objects.create(user=instance).save()
except Exception as err:
print('Error creating basis user profile!')
print(err)
Upvotes: 0
Views: 519
Reputation: 96
So, i just needed to spend 5 hour and/or post on here. The issue is not a django issue but one related to the tool i'm using for AAD/SSO: django-auth-adfs.
After combing over the docs again, i find that the GROUPS_CLAIM is not explicitly set to None, it will remove all groups from the django groups assignment for the user. I set this to None and what do you know.. it works!!
Posting this resolution to help some other poor soul who gets lost and traverses through a lot of older posts wondering why it just doesn't show up. In the end, read the docs.. all the docs.
Upvotes: 2