Skip to content

Commit b755074

Browse files
committed
_msal_managed_identity
1 parent 76f68de commit b755074

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/azure-cli-core/azure/cli/core/_profile.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def login(self,
217217

218218
def login_with_managed_identity(self, identity_id=None, allow_no_subscriptions=None):
219219
identity_type = None
220-
if _on_azure_arc():
220+
if _msal_managed_identity():
221221
identity_type = MsiAccountTypes.system_assigned
222222
from .auth.msal_authentication import ManagedIdentityCredential
223223
cred = ManagedIdentityCredential()
@@ -372,7 +372,7 @@ def get_login_credentials(self, resource=None, client_id=None, subscription_id=N
372372
resource=resource)
373373
else:
374374
# managed identity
375-
if _on_azure_arc():
375+
if _msal_managed_identity():
376376
from .auth.msal_authentication import ManagedIdentityCredential
377377
cred = ManagedIdentityCredential()
378378
else:
@@ -402,7 +402,7 @@ def get_raw_token(self, resource=None, scopes=None, subscription=None, tenant=No
402402
if tenant:
403403
raise CLIError("Tenant shouldn't be specified for managed identity account")
404404
from .auth.util import scopes_to_resource
405-
if _on_azure_arc():
405+
if _msal_managed_identity():
406406
from .auth.msal_authentication import ManagedIdentityCredential
407407
cred = ManagedIdentityCredential()
408408
else:
@@ -917,5 +917,9 @@ def _create_identity_instance(cli_ctx, *args, **kwargs):
917917
instance_discovery=instance_discovery, **kwargs)
918918

919919

920-
def _on_azure_arc():
921-
return "IDENTITY_ENDPOINT" in os.environ and "IMDS_ENDPOINT" in os.environ
920+
def _msal_managed_identity():
921+
# Azure Arc
922+
if "IDENTITY_ENDPOINT" in os.environ and "IMDS_ENDPOINT" in os.environ:
923+
logger.debug("Azure Arc detected")
924+
return True
925+
return False

src/azure-cli-core/azure/cli/core/auth/msal_authentication.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ def get_token(self, *scopes, **kwargs):
142142

143143

144144
class ManagedIdentityCredential: # pylint: disable=too-few-public-methods
145-
"""Currently, only Azure Arc's system-assigned managed identity is supported.
145+
"""Managed identity credential implementing get_token interface.
146+
147+
It uses MSAL internally.
148+
149+
Currently, only Azure Arc's system-assigned managed identity is supported.
146150
"""
147151

148152
def __init__(self):

0 commit comments

Comments
 (0)