@@ -72,6 +72,8 @@ class DefaultAzureCredential(ChainedTokenCredential):
7272 of the environment variable AZURE_CLIENT_ID, if any. If not specified, a system-assigned identity will be used.
7373 :keyword str workload_identity_client_id: The client ID of an identity assigned to the pod. Defaults to the value
7474 of the environment variable AZURE_CLIENT_ID, if any. If not specified, the pod's default identity will be used.
75+ :keyword str workload_identity_tenant_id: Preferred tenant for :class:`~azure.identity.WorkloadIdentityCredential`.
76+ Defaults to the value of environment variable AZURE_TENANT_ID, if any.
7577 :keyword str interactive_browser_client_id: The client ID to be used in interactive browser credential. If not
7678 specified, users will authenticate to an Azure development application.
7779 :keyword str shared_cache_username: Preferred username for :class:`~azure.identity.SharedTokenCacheCredential`.
@@ -95,7 +97,7 @@ class DefaultAzureCredential(ChainedTokenCredential):
9597 :caption: Create a DefaultAzureCredential.
9698 """
9799
98- def __init__ (self , ** kwargs : Any ) -> None : # pylint: disable=too-many-statements
100+ def __init__ (self , ** kwargs : Any ) -> None : # pylint: disable=too-many-statements, too-many-locals
99101 if "tenant_id" in kwargs :
100102 raise TypeError ("'tenant_id' is not supported in DefaultAzureCredential." )
101103
@@ -122,6 +124,9 @@ def __init__(self, **kwargs: Any) -> None: # pylint: disable=too-many-statement
122124 workload_identity_client_id = kwargs .pop (
123125 "workload_identity_client_id" , managed_identity_client_id
124126 )
127+ workload_identity_tenant_id = kwargs .pop (
128+ "workload_identity_tenant_id" , os .environ .get (EnvironmentVariables .AZURE_TENANT_ID )
129+ )
125130 interactive_browser_client_id = kwargs .pop ("interactive_browser_client_id" , None )
126131
127132 shared_cache_username = kwargs .pop ("shared_cache_username" , os .environ .get (EnvironmentVariables .AZURE_USERNAME ))
@@ -149,7 +154,7 @@ def __init__(self, **kwargs: Any) -> None: # pylint: disable=too-many-statement
149154 client_id = workload_identity_client_id
150155 credentials .append (WorkloadIdentityCredential (
151156 client_id = cast (str , client_id ),
152- tenant_id = os . environ [ EnvironmentVariables . AZURE_TENANT_ID ] ,
157+ tenant_id = workload_identity_tenant_id ,
153158 file = os .environ [EnvironmentVariables .AZURE_FEDERATED_TOKEN_FILE ],
154159 ** kwargs ))
155160 if not exclude_managed_identity_credential :
0 commit comments