Skip to content

Commit 9ada103

Browse files
committed
_generate_msal_kwargs
1 parent 4c39567 commit 9ada103

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,15 @@ def get_token(self, *scopes, **kwargs):
2727
"""Get an access token from the main credential."""
2828
logger.debug("CredentialAdaptor.get_token: scopes=%r, kwargs=%r", scopes, kwargs)
2929

30-
# Discard unsupported kwargs: tenant_id, enable_cae
31-
filtered_kwargs = {}
32-
if 'data' in kwargs:
33-
filtered_kwargs['data'] = kwargs['data']
34-
35-
return build_sdk_access_token(self._credential.acquire_token(list(scopes), **filtered_kwargs))
30+
msal_kwargs = _generate_msal_kwargs(kwargs)
31+
return build_sdk_access_token(self._credential.acquire_token(list(scopes), **msal_kwargs))
3632

3733

3834
def get_token_info(self, *scopes, options=None):
3935
"""Get an access token from the main credential."""
4036
logger.debug("CredentialAdaptor.get_token_info: scopes=%r, options=%r", scopes, options)
4137

42-
# Discard unsupported kwargs: tenant_id, enable_cae
43-
msal_kwargs = {}
44-
if 'claims' in options:
45-
msal_kwargs['claims'] = options['claims']
46-
if 'data' in options:
47-
msal_kwargs['data'] = options['data']
48-
38+
msal_kwargs = _generate_msal_kwargs(options)
4939
return _build_sdk_access_token_info(self._credential.acquire_token(list(scopes), **msal_kwargs))
5040

5141

@@ -58,6 +48,20 @@ def get_auxiliary_tokens(self, *scopes, **kwargs):
5848
return None
5949

6050

51+
def _generate_msal_kwargs(options=None):
52+
# Preserve supported options and discard unsupported options (tenant_id, enable_cae).
53+
# Both get_token's kwargs and get_token_info's options are accepted as their schema is the same (at least for now).
54+
msal_kwargs = {}
55+
if options:
56+
# For VM SSH
57+
if 'data' in options:
58+
msal_kwargs['data'] = options['data']
59+
# For CAE
60+
if 'claims' in options:
61+
msal_kwargs['claims'] = options['claims']
62+
return msal_kwargs
63+
64+
6165
def _build_sdk_access_token_info(token_entry):
6266
# MSAL token entry sample:
6367
# {

0 commit comments

Comments
 (0)