From 3cb5ba7fa9ec5ed0b0dfb5d02139e8d50cca3b35 Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 17 Aug 2023 08:32:52 -0700 Subject: [PATCH] 11508 review changes - add error checking --- netbox/netbox/authentication.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/netbox/netbox/authentication.py b/netbox/netbox/authentication.py index 355481043..7c093621f 100644 --- a/netbox/netbox/authentication.py +++ b/netbox/netbox/authentication.py @@ -443,12 +443,16 @@ def azuread_map_groups(response, user, backend, *args, **kwargs): # Set groups and permissions based on returned group list is_superuser = False is_staff = False - values = response.json().get('value', []) + try: + values = response.json().get('value', []) + except Exception as e: + logger.error(f"Azure AD group mapping error getting groups json response for user {user} from Microsoft Graph API: {e}") + raise e user.groups.through.objects.filter(user=user).delete() for value in values: # AD response contains both directories and groups - we only want groups - if value.get('@odata.type') == '#microsoft.graph.group': + if value.get('@odata.type', None) == '#microsoft.graph.group': group_id = value.get('id', None) if group_id in flags_by_group['is_superuser']: