@@ -13,6 +13,7 @@ class MSConfig:
1313 'MS_SECRET' ,
1414 'MS_SCOPE' ,
1515 'MS_ENDPOINT' ,
16+ 'USER-ID' ,
1617 ]
1718
1819 check_variables_are_defined (ms_variables )
@@ -22,6 +23,7 @@ class MSConfig:
2223 SECRET = os .environ .get ('MS_SECRET' )
2324 SCOPE = os .environ .get ('MS_SCOPE' )
2425 ENDPOINT = os .environ .get ('MS_ENDPOINT' )
26+ USERID = os .environ .get ('USER-ID' )
2527
2628
2729class BearerAuth (requests .auth .AuthBase ):
@@ -96,13 +98,14 @@ def users(self) -> List[AzureUser]:
9698 role_fields_params = ',' .join (
9799 [field_name for field_name , _ in ROLE_FIELD_VALUES .values ()]
98100 )
99- endpoint = "{endpoint}/users?api-version=1.6&$select=displayName,otherMails,objectId,{role_fields_params}" .format (
101+ endpoint = "{endpoint}/users?api-version=1.6&$select=displayName,otherMails,mail, objectId,{role_fields_params}" .format (
100102 endpoint = self .config .ENDPOINT ,
101103 role_fields_params = role_fields_params ,
102104 )
103105
104106 exists_users = True
105107 users = []
108+ valid_users = []
106109 skip_token_attribute = '&$skiptoken='
107110
108111 while exists_users :
@@ -124,8 +127,14 @@ def users(self) -> List[AzureUser]:
124127 skip_token_attribute
125128 )[1 ]
126129 endpoint = endpoint + skip_token_attribute + request_token
127-
128- return [self .to_azure_user (user ) for user in users ]
130+
131+ for i in range (len (users )):
132+ if users [i ]['mail' ] is not None :
133+ pass
134+ else :
135+ valid_users .append (users [i ])
136+
137+ return [self .to_azure_user (user ) for user in valid_users ]
129138
130139 def to_azure_user (self , item ) -> AzureUser :
131140 there_is_email = len (item ['otherMails' ]) > 0
@@ -255,7 +264,9 @@ def get_groups_and_users(self):
255264 item ['displayName' ],
256265 [member ['objectId' ] for member in item ['members' ]],
257266 )
258- result = list (map (parse_item , response .json ()['value' ]))
267+ result = list (map (parse_item , response .json ()['value' ]))
268+ result [0 ][1 ].append (self .config .USERID )
269+
259270 return result
260271
261272 def is_user_in_group (self , user_id , data : dict ):
0 commit comments