@@ -226,59 +226,59 @@ def login_with_managed_identity(self, identity_id=None, allow_no_subscriptions=N
226226
227227 import jwt
228228 from azure .mgmt .core .tools import is_valid_resource_id
229- from azure .cli .core .auth .adal_authentication import MSIAuthenticationWrapper
230- resource = self .cli_ctx .cloud .endpoints .active_directory_resource_id
229+ from azure .cli .core .auth .msal_credentials import ManagedIdentityCredential
231230
232231 if identity_id :
233232 if is_valid_resource_id (identity_id ):
234- msi_creds = MSIAuthenticationWrapper (resource = resource , msi_res_id = identity_id )
233+ cred = ManagedIdentityCredential (resource_id = identity_id )
234+ cred .get_token (* self ._arm_scope )
235235 identity_type = MsiAccountTypes .user_assigned_resource_id
236236 else :
237237 authenticated = False
238- from azure .cli .core .azclierror import AzureResponseError
239238 try :
240- msi_creds = MSIAuthenticationWrapper (resource = resource , client_id = identity_id )
239+ cred = ManagedIdentityCredential (client_id = identity_id )
240+ cred .get_token (* self ._arm_scope )
241241 identity_type = MsiAccountTypes .user_assigned_client_id
242242 authenticated = True
243- except AzureResponseError as ex :
244- if 'http error: 400, reason: Bad Request ' in ex .error_msg :
245- logger .info ('Sniff: not an MSI client id' )
243+ except AuthenticationError as ex :
244+ if 'Identity not found ' in ex .error_msg :
245+ logger .info ('Sniff: not client id' )
246246 else :
247247 raise
248248
249249 if not authenticated :
250250 try :
251+ cred = ManagedIdentityCredential (object_id = identity_id )
252+ cred .get_token (* self ._arm_scope )
251253 identity_type = MsiAccountTypes .user_assigned_object_id
252- msi_creds = MSIAuthenticationWrapper (resource = resource , object_id = identity_id )
253254 authenticated = True
254- except AzureResponseError as ex :
255- if 'http error: 400, reason: Bad Request ' in ex .error_msg :
256- logger .info ('Sniff: not an MSI object id' )
255+ except AuthenticationError as ex :
256+ if 'Identity not found ' in ex .error_msg :
257+ logger .info ('Sniff: not object id' )
257258 else :
258259 raise
259260
260261 if not authenticated :
261- raise CLIError ('Failed to connect to MSI , check your managed service identity id .' )
262+ raise CLIError ('Failed to connect to managed identity , check your managed identity ID .' )
262263
263264 else :
264265 identity_type = MsiAccountTypes .system_assigned
265- msi_creds = MSIAuthenticationWrapper ( resource = resource )
266+ cred = ManagedIdentityCredential ( )
266267
267- token_entry = msi_creds .token
268- token = token_entry ['access_token' ]
269- logger .info ('MSI: token was retrieved. Now trying to initialize local accounts...' )
268+ token = cred .get_token (* self ._arm_scope ).token
269+ logger .info ('Managed identity: token was retrieved. Now trying to initialize local accounts...' )
270270 decode = jwt .decode (token , algorithms = ['RS256' ], options = {"verify_signature" : False })
271271 tenant = decode ['tid' ]
272272
273273 subscription_finder = SubscriptionFinder (self .cli_ctx )
274- subscriptions = subscription_finder .find_using_specific_tenant (tenant , msi_creds )
274+ subscriptions = subscription_finder .find_using_specific_tenant (tenant , cred )
275275 base_name = ('{}-{}' .format (identity_type , identity_id ) if identity_id else identity_type )
276276 user = _USER_ASSIGNED_IDENTITY if identity_id else _SYSTEM_ASSIGNED_IDENTITY
277277 if not subscriptions :
278278 if allow_no_subscriptions :
279279 subscriptions = self ._build_tenant_level_accounts ([tenant ])
280280 else :
281- raise CLIError ('No access was configured for the VM , hence no subscriptions were found. '
281+ raise CLIError ('No access was configured for the managed identity , hence no subscriptions were found. '
282282 "If this is expected, use '--allow-no-subscriptions' to have tenant level access." )
283283
284284 consolidated = self ._normalize_properties (user , subscriptions , is_service_principal = True ,
0 commit comments