@@ -220,27 +220,24 @@ def login(self,
220220 self ._set_subscriptions (consolidated )
221221 return deepcopy (consolidated )
222222
223- def login_with_managed_identity (self , identity_id = None , client_id = None , object_id = None , resource_id = None ,
223+ def login_with_managed_identity (self , client_id = None , object_id = None , resource_id = None ,
224224 allow_no_subscriptions = None ):
225225 if _use_msal_managed_identity (self .cli_ctx ):
226- if identity_id :
227- raise CLIError ('--username is not supported by MSAL managed identity. '
228- 'Use --client-id, --object-id or --resource-id instead.' )
229226 return self .login_with_managed_identity_msal (
230227 client_id = client_id , object_id = object_id , resource_id = resource_id ,
231228 allow_no_subscriptions = allow_no_subscriptions )
232229
233230 import jwt
234- from azure .mgmt .core .tools import is_valid_resource_id
235231 from azure .cli .core .auth .adal_authentication import MSIAuthenticationWrapper
236232 resource = self .cli_ctx .cloud .endpoints .active_directory_resource_id
237233
238- id_arg_count = len ([arg for arg in (client_id , object_id , resource_id , identity_id ) if arg ])
234+ id_arg_count = len ([arg for arg in (client_id , object_id , resource_id ) if arg ])
239235 if id_arg_count > 1 :
240- raise CLIError ('Usage error: Provide only one of --client-id, --object-id, --resource-id, or --username .' )
236+ raise CLIError ('Usage error: Provide only one of --client-id, --object-id, --resource-id.' )
241237
242238 if id_arg_count == 0 :
243239 identity_type = MsiAccountTypes .system_assigned
240+ identity_id = None
244241 msi_creds = MSIAuthenticationWrapper (resource = resource )
245242 elif client_id :
246243 identity_type = MsiAccountTypes .user_assigned_client_id
@@ -254,37 +251,6 @@ def login_with_managed_identity(self, identity_id=None, client_id=None, object_i
254251 identity_type = MsiAccountTypes .user_assigned_resource_id
255252 identity_id = resource_id
256253 msi_creds = MSIAuthenticationWrapper (resource = resource , msi_res_id = resource_id )
257- # The old way of re-using the same --username for 3 types of ID
258- elif identity_id :
259- if is_valid_resource_id (identity_id ):
260- msi_creds = MSIAuthenticationWrapper (resource = resource , msi_res_id = identity_id )
261- identity_type = MsiAccountTypes .user_assigned_resource_id
262- else :
263- authenticated = False
264- from azure .cli .core .azclierror import AzureResponseError
265- try :
266- msi_creds = MSIAuthenticationWrapper (resource = resource , client_id = identity_id )
267- identity_type = MsiAccountTypes .user_assigned_client_id
268- authenticated = True
269- except AzureResponseError as ex :
270- if 'http error: 400, reason: Bad Request' in ex .error_msg :
271- logger .info ('Sniff: not an MSI client id' )
272- else :
273- raise
274-
275- if not authenticated :
276- try :
277- identity_type = MsiAccountTypes .user_assigned_object_id
278- msi_creds = MSIAuthenticationWrapper (resource = resource , object_id = identity_id )
279- authenticated = True
280- except AzureResponseError as ex :
281- if 'http error: 400, reason: Bad Request' in ex .error_msg :
282- logger .info ('Sniff: not an MSI object id' )
283- else :
284- raise
285-
286- if not authenticated :
287- raise CLIError ('Failed to connect to MSI, check your managed service identity id.' )
288254
289255 token_entry = msi_creds .token
290256 token = token_entry ['access_token' ]
0 commit comments