Skip to content

Commit d0e6cbb

Browse files
committed
client_id
1 parent 46da4e9 commit d0e6cbb

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,10 @@ def logout_all(self):
362362
identity.logout_all_users()
363363
identity.logout_all_service_principal()
364364

365-
def get_login_credentials(self, resource=None, client_id=None, subscription_id=None, aux_subscriptions=None,
366-
aux_tenants=None):
365+
def get_login_credentials(self, resource=None, subscription_id=None, aux_subscriptions=None, aux_tenants=None):
367366
"""Get a CredentialAdaptor instance to be used with both Track 1 and Track 2 SDKs.
368367
369368
:param resource: The resource ID to acquire an access token. Only provide it for Track 1 SDKs.
370-
:param client_id:
371369
:param subscription_id:
372370
:param aux_subscriptions:
373371
:param aux_tenants:
@@ -410,10 +408,10 @@ def get_login_credentials(self, resource=None, client_id=None, subscription_id=N
410408
if sub[_TENANT_ID] != account[_TENANT_ID]:
411409
external_tenants.append(sub[_TENANT_ID])
412410

413-
credential = self._create_credential(account, client_id=client_id)
411+
credential = self._create_credential(account)
414412
external_credentials = []
415413
for external_tenant in external_tenants:
416-
external_credentials.append(self._create_credential(account, external_tenant, client_id=client_id))
414+
external_credentials.append(self._create_credential(account, tenant_id=external_tenant))
417415
from azure.cli.core.auth.credential_adaptor import CredentialAdaptor
418416
cred = CredentialAdaptor(credential,
419417
auxiliary_credentials=external_credentials,
@@ -423,7 +421,7 @@ def get_login_credentials(self, resource=None, client_id=None, subscription_id=N
423421
str(account[_SUBSCRIPTION_ID]),
424422
str(account[_TENANT_ID]))
425423

426-
def get_raw_token(self, resource=None, scopes=None, subscription=None, tenant=None):
424+
def get_raw_token(self, resource=None, scopes=None, subscription=None, tenant=None, client_id=None):
427425
# Convert resource to scopes
428426
if resource and not scopes:
429427
from .auth.util import resource_to_scopes
@@ -460,7 +458,7 @@ def get_raw_token(self, resource=None, scopes=None, subscription=None, tenant=No
460458
scopes_to_resource(scopes))
461459

462460
else:
463-
cred = self._create_credential(account, tenant)
461+
cred = self._create_credential(account, tenant_id=tenant, client_id=client_id)
464462

465463
sdk_token = cred.get_token(*scopes)
466464
# Convert epoch int 'expires_on' to datetime string 'expiresOn' for backward compatibility
@@ -665,7 +663,7 @@ def _create_credential(self, account, tenant_id=None, client_id=None):
665663
"""
666664
user_type = account[_USER_ENTITY][_USER_TYPE]
667665
username_or_sp_id = account[_USER_ENTITY][_USER_NAME]
668-
tenant_id = tenant_id if tenant_id else account[_TENANT_ID]
666+
tenant_id = tenant_id or account[_TENANT_ID]
669667
identity = _create_identity_instance(self.cli_ctx, self._authority, tenant_id=tenant_id, client_id=client_id)
670668

671669
# User
@@ -694,7 +692,7 @@ def refresh_accounts(self):
694692
tenant = s[_TENANT_ID]
695693
subscriptions = []
696694
try:
697-
identity_credential = self._create_credential(s, tenant)
695+
identity_credential = self._create_credential(s, tenant_id=tenant)
698696
if is_service_principal:
699697
subscriptions = subscription_finder.find_using_specific_tenant(tenant, identity_credential)
700698
else:
@@ -938,7 +936,7 @@ def _transform_subscription_for_multiapi(s, s_dict):
938936
s_dict[_MANAGED_BY_TENANTS] = [{_TENANT_ID: t.tenant_id} for t in s.managed_by_tenants]
939937

940938

941-
def _create_identity_instance(cli_ctx, *args, **kwargs):
939+
def _create_identity_instance(cli_ctx, authority, tenant_id=None, client_id=None):
942940
"""Lazily import and create Identity instance to avoid unnecessary imports."""
943941
from .auth.identity import Identity
944942
from .util import should_encrypt_token_cache
@@ -955,9 +953,11 @@ def _create_identity_instance(cli_ctx, *args, **kwargs):
955953
# PREVIEW: In Azure Stack environment, use core.instance_discovery=false to disable MSAL's instance discovery.
956954
instance_discovery = cli_ctx.config.getboolean('core', 'instance_discovery', True)
957955

958-
return Identity(*args, encrypt=encrypt, use_msal_http_cache=use_msal_http_cache,
956+
return Identity(authority, tenant_id=tenant_id, client_id=client_id,
957+
encrypt=encrypt,
958+
use_msal_http_cache=use_msal_http_cache,
959959
enable_broker_on_windows=enable_broker_on_windows,
960-
instance_discovery=instance_discovery, **kwargs)
960+
instance_discovery=instance_discovery)
961961

962962

963963
def _on_azure_arc_windows():

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def __init__(self, authority, tenant_id=None, client_id=None, encrypt=False, use
7373
"""
7474
self.authority = authority
7575
self.tenant_id = tenant_id
76+
# This client ID is only used for PublicClientApplication, not ConfidentialClientApplication
7677
self.client_id = client_id or AZURE_CLI_CLIENT_ID
7778
self._encrypt = encrypt
7879
self._use_msal_http_cache = use_msal_http_cache

src/azure-cli/azure/cli/command_modules/profile/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ def load_arguments(self, command):
101101
c.argument('tenant', options_list=['--tenant', '-t'],
102102
help='Tenant ID for which the token is acquired. Only available for user and service principal '
103103
'account, not for managed identity or Cloud Shell account')
104+
c.argument('client_id',
105+
help='A first-party app ID that can do single sign-on with Azure CLI.')
104106

105107

106108
COMMAND_LOADER_CLS = ProfileCommandsLoader

src/azure-cli/azure/cli/command_modules/profile/custom.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ def show_subscription(cmd, subscription=None):
7070
return profile.get_subscription(subscription)
7171

7272

73-
def get_access_token(cmd, subscription=None, resource=None, scopes=None, resource_type=None, tenant=None):
73+
def get_access_token(cmd, subscription=None, resource=None, scopes=None, resource_type=None, tenant=None,
74+
client_id=None):
7475
"""
7576
get AAD token to access to a specified resource.
7677
Use 'az cloud show' command for other Azure resources
@@ -80,8 +81,8 @@ def get_access_token(cmd, subscription=None, resource=None, scopes=None, resourc
8081
resource = getattr(cmd.cli_ctx.cloud.endpoints, endpoints_attr_name)
8182

8283
profile = Profile(cli_ctx=cmd.cli_ctx)
83-
creds, subscription, tenant = profile.get_raw_token(subscription=subscription, resource=resource, scopes=scopes,
84-
tenant=tenant)
84+
creds, subscription, tenant = profile.get_raw_token(
85+
subscription=subscription, resource=resource, scopes=scopes, tenant=tenant, client_id=client_id)
8586

8687
result = {
8788
'tokenType': creds[0],

0 commit comments

Comments
 (0)