@@ -55,6 +55,8 @@ def __init__(self, config=MSConfig):
5555 self .config = config
5656 self .access_token = self .get_token ()
5757
58+ self .role_field = 'extension_1d76efa96f604499acc0c0ee116a1453_role'
59+
5860 def get_token (self ):
5961 response = self .client .acquire_token_for_client (
6062 scopes = self .config .SCOPE
@@ -67,8 +69,7 @@ def get_token(self):
6769
6870 def users (self ) -> List [AzureUser ]:
6971 endpoint = "{endpoint}/users?api-version=1.6&$select=displayName,otherMails,objectId,{role_field}" .format (
70- endpoint = self .config .ENDPOINT ,
71- role_field = 'extension_1d76efa96f604499acc0c0ee116a1453_role' ,
72+ endpoint = self .config .ENDPOINT , role_field = self .role_field ,
7273 )
7374 response = requests .get (endpoint , auth = BearerAuth (self .access_token ))
7475
@@ -84,7 +85,7 @@ def update_user_role(self, id, role):
8485 endpoint = "{endpoint}/users/{user_id}?api-version=1.6" .format (
8586 endpoint = self .config .ENDPOINT , user_id = id
8687 )
87- data = {'extension_1d76efa96f604499acc0c0ee116a1453_role' : role }
88+ data = {self . role_field : role }
8889 response = requests .patch (
8990 endpoint ,
9091 auth = BearerAuth (self .access_token ),
@@ -100,16 +101,10 @@ def update_user_role(self, id, role):
100101
101102 def to_azure_user (self , item ) -> AzureUser :
102103 there_is_email = len (item ['otherMails' ]) > 0
103- there_is_role = (
104- 'extension_1d76efa96f604499acc0c0ee116a1453_role' in item
105- )
104+ there_is_role = self .role_field in item
106105
107106 id = item ['objectId' ]
108107 name = item ['displayName' ]
109108 email = item ['otherMails' ][0 ] if there_is_email else ''
110- role = (
111- item ['extension_1d76efa96f604499acc0c0ee116a1453_role' ]
112- if there_is_role
113- else None
114- )
109+ role = item [self .role_field ] if there_is_role else None
115110 return AzureUser (id , name , email , role )
0 commit comments