@@ -379,7 +379,7 @@ def get_login_credentials(self, resource=None, client_id=None, subscription_id=N
379379
380380 account = self .get_subscription (subscription_id )
381381
382- managed_identity_type , managed_identity_id = Profile ._try_parse_msi_account_name (account )
382+ managed_identity_type , managed_identity_id = Profile ._parse_managed_identity_account (account )
383383
384384 if in_cloud_console () and account [_USER_ENTITY ].get (_CLOUD_SHELL_ID ):
385385 # Cloud Shell
@@ -438,7 +438,7 @@ def get_raw_token(self, resource=None, scopes=None, subscription=None, tenant=No
438438
439439 account = self .get_subscription (subscription )
440440
441- managed_identity_type , managed_identity_id = Profile ._try_parse_msi_account_name (account )
441+ managed_identity_type , managed_identity_id = Profile ._parse_managed_identity_account (account )
442442
443443 if in_cloud_console () and account [_USER_ENTITY ].get (_CLOUD_SHELL_ID ):
444444 # Cloud Shell
@@ -644,15 +644,20 @@ def get_subscription_id(self, subscription=None): # take id or name
644644 return self .get_subscription (subscription )[_SUBSCRIPTION_ID ]
645645
646646 @staticmethod
647- def _try_parse_msi_account_name (account ):
648- msi_info , user = account [_USER_ENTITY ].get (_ASSIGNED_IDENTITY_INFO ), account [_USER_ENTITY ].get (_USER_NAME )
649-
650- if user in [_SYSTEM_ASSIGNED_IDENTITY , _USER_ASSIGNED_IDENTITY ]:
651- if not msi_info :
652- msi_info = account [_SUBSCRIPTION_NAME ] # fall back to old persisting way
653- parts = msi_info .split ('-' , 1 )
654- if parts [0 ] in MsiAccountTypes .valid_msi_account_types ():
655- return parts [0 ], (None if len (parts ) <= 1 else parts [1 ])
647+ def _parse_managed_identity_account (account ):
648+ user_name = account [_USER_ENTITY ].get (_USER_NAME )
649+ assigned_identity_info = account [_USER_ENTITY ].get (_ASSIGNED_IDENTITY_INFO )
650+
651+ if user_name == _SYSTEM_ASSIGNED_IDENTITY :
652+ # The account contains:
653+ # "assignedIdentityInfo": "MSI",
654+ # "name": "systemAssignedIdentity",
655+ return assigned_identity_info , None
656+ if user_name == _USER_ASSIGNED_IDENTITY :
657+ # The account contains:
658+ # "assignedIdentityInfo": "MSIClient-xxx"/"MSIObject-xxx"/"MSIResource-xxx",
659+ # "name": "userAssignedIdentity",
660+ return tuple (assigned_identity_info .split ('-' , 1 ))
656661 return None , None
657662
658663 def _create_credential (self , account , tenant_id = None , client_id = None ):
0 commit comments