docs: def update_user_groups(self, user, claims):
          """
          Updates user group memberships based on the GROUPS_CLAIM setting.
  
          Args:
              user (django.contrib.auth.models.User): User model instance
              claims (dict): Claims from the access token
          """
          if settings.GROUPS_CLAIM is not None:
              # Update the user's group memberships
              django_groups = [group.name for group in user.groups.all()]
  
              if settings.GROUPS_CLAIM in claims:
                  claim_groups = claims[settings.GROUPS_CLAIM]
                  if not isinstance(claim_groups, list):
                      claim_groups = [claim_groups, ]
              else:
                  logger.debug(
                      "The configured groups claim '{}' was not found in the access token".format(settings.GROUPS_CLAIM))
                  claim_groups = []
  
              # Make a diff of the user's groups.
              # Removing a user from all groups and then re-add them would cause
              # the autoincrement value for the database table storing the
              # user-to-group mappings to increment for no reason.
              groups_to_remove = set(django_groups) - set(claim_groups)
              groups_to_add = set(claim_groups) - set(django_groups)
  
              # Loop through the groups in the group claim and
              # add the user to these groups as needed.
              for group_name in groups_to_remove:
                  group = Group.objects.get(name=group_name)
                  user.groups.remove(group)
                  logger.debug("User removed from group '{}'".format(group_name))
  
              for group_name in groups_to_add:
                  try:
                      if settings.MIRROR_GROUPS:
                          group, _ = Group.objects.get_or_create(name=group_name)
                          logger.debug("Created group '{}'".format(group_name))
                      else:
                          group = Group.objects.get(name=group_name)
                      user.groups.add(group)
                      logger.debug("User added to group '{}'".format(group_name))
                  except ObjectDoesNotExist:
                      # Silently fail for non-existing groups.
                      pass