@@ -43,16 +43,23 @@ def __init__(self, client_id, username, **kwargs):
4343
4444 self ._account = accounts [0 ]
4545
46- def acquire_token (self , scopes , claims_challenge = None , ** kwargs ):
46+ def acquire_token (self , scopes , claims_challenge = None , data = None , ** kwargs ):
4747 # scopes must be a list.
4848 # For acquiring SSH certificate, scopes is ['https://pas.windows.net/CheckMyAccess/Linux/.default']
49+ # data is only used for acquiring VM SSH certificate. DO NOT use it for other purposes.
4950 # kwargs is already sanitized by CredentialAdaptor, so it can be safely passed to MSAL
50- logger .debug ("UserCredential.acquire_token: scopes=%r, claims_challenge=%r, kwargs=%r" ,
51- scopes , claims_challenge , kwargs )
51+ logger .debug ("UserCredential.acquire_token: scopes=%r, claims_challenge=%r, data=%r, kwargs=%r" ,
52+ scopes , claims_challenge , data , kwargs )
5253
5354 if claims_challenge :
5455 logger .warning ('Acquiring new access token silently for tenant %s with claims challenge: %s' ,
5556 self ._msal_app .authority .tenant , claims_challenge )
57+
58+ # Only pass data to MSAL if it is set. Passing data=None will cause failure in MSAL:
59+ # AttributeError: 'NoneType' object has no attribute 'get'
60+ if data is not None :
61+ kwargs ['data' ] = data
62+
5663 result = self ._msal_app .acquire_token_silent_with_error (
5764 scopes , self ._account , claims_challenge = claims_challenge , ** kwargs )
5865
@@ -105,8 +112,13 @@ def __init__(self, client_id, client_credential, **kwargs):
105112 """
106113 self ._msal_app = ConfidentialClientApplication (client_id , client_credential = client_credential , ** kwargs )
107114
108- def acquire_token (self , scopes , ** kwargs ):
109- logger .debug ("ServicePrincipalCredential.acquire_token: scopes=%r, kwargs=%r" , scopes , kwargs )
115+ def acquire_token (self , scopes , data = None , ** kwargs ):
116+ logger .debug ("ServicePrincipalCredential.acquire_token: scopes=%r, data=%r, kwargs=%r" ,
117+ scopes , data , kwargs )
118+
119+ if data is not None :
120+ kwargs ['data' ] = data
121+
110122 result = self ._msal_app .acquire_token_for_client (scopes , ** kwargs )
111123 check_result (result )
112124 return result
@@ -126,8 +138,13 @@ def __init__(self):
126138 # token_cache=...
127139 )
128140
129- def acquire_token (self , scopes , ** kwargs ):
130- logger .debug ("CloudShellCredential.acquire_token: scopes=%r, kwargs=%r" , scopes , kwargs )
141+ def acquire_token (self , scopes , data = None , ** kwargs ):
142+ logger .debug ("CloudShellCredential.acquire_token: scopes=%r, data=%r, kwargs=%r" ,
143+ scopes , data , kwargs )
144+
145+ if data is not None :
146+ kwargs ['data' ] = data
147+
131148 result = self ._msal_app .acquire_token_interactive (scopes , prompt = "none" , ** kwargs )
132149 check_result (result , scopes = scopes )
133150 return result
@@ -147,8 +164,13 @@ def __init__(self, client_id=None, resource_id=None, object_id=None):
147164 managed_identity = SystemAssignedManagedIdentity ()
148165 self ._msal_client = ManagedIdentityClient (managed_identity , http_client = requests .Session ())
149166
150- def acquire_token (self , scopes , ** kwargs ):
151- logger .debug ("ManagedIdentityCredential.acquire_token: scopes=%r, kwargs=%r" , scopes , kwargs )
167+ def acquire_token (self , scopes , data = None , ** kwargs ):
168+ logger .debug ("ManagedIdentityCredential.acquire_token: scopes=%r, data=%r, kwargs=%r" ,
169+ scopes , data , kwargs )
170+
171+ if data is not None :
172+ from azure .cli .core .azclierror import AuthenticationError
173+ raise AuthenticationError ("VM SSH currently doesn't support managed identity." )
152174
153175 from .util import scopes_to_resource
154176 result = self ._msal_client .acquire_token_for_client (resource = scopes_to_resource (scopes ))
0 commit comments