14
14
from .environment import EnvironmentCredential
15
15
from .managed_identity import ManagedIdentityCredential
16
16
from .shared_cache import SharedTokenCacheCredential
17
+ from .vscode import VisualStudioCodeCredential
17
18
18
19
if TYPE_CHECKING :
19
20
from typing import Any , List
@@ -47,6 +48,8 @@ class DefaultAzureCredential(ChainedTokenCredential):
47
48
:keyword bool exclude_environment_credential: Whether to exclude a service principal configured by environment
48
49
variables from the credential. Defaults to **False**.
49
50
:keyword bool exclude_powershell_credential: Whether to exclude Azure PowerShell. Defaults to **False**.
51
+ :keyword bool exclude_visual_studio_code_credential: Whether to exclude stored credential from VS Code.
52
+ Defaults to **True**.
50
53
:keyword bool exclude_managed_identity_credential: Whether to exclude managed identity from the credential.
51
54
Defaults to **False**.
52
55
:keyword bool exclude_shared_token_cache_credential: Whether to exclude the shared token cache. Defaults to
@@ -57,6 +60,10 @@ class DefaultAzureCredential(ChainedTokenCredential):
57
60
Defaults to the value of environment variable AZURE_USERNAME, if any.
58
61
:keyword str shared_cache_tenant_id: Preferred tenant for :class:`~azure.identity.aio.SharedTokenCacheCredential`.
59
62
Defaults to the value of environment variable AZURE_TENANT_ID, if any.
63
+ :keyword str visual_studio_code_tenant_id: Tenant ID to use when authenticating with
64
+ :class:`~azure.identity.aio.VisualStudioCodeCredential`. Defaults to the "Azure: Tenant" setting in VS Code's
65
+ user settings or, when that setting has no value, the "organizations" tenant, which supports only Azure Active
66
+ Directory work or school accounts.
60
67
"""
61
68
62
69
def __init__ (self , ** kwargs : "Any" ) -> None :
@@ -65,6 +72,15 @@ def __init__(self, **kwargs: "Any") -> None:
65
72
66
73
authority = kwargs .pop ("authority" , None )
67
74
75
+ vscode_tenant_id = kwargs .pop (
76
+ "visual_studio_code_tenant_id" , os .environ .get (EnvironmentVariables .AZURE_TENANT_ID )
77
+ )
78
+ vscode_args = dict (kwargs )
79
+ if authority :
80
+ vscode_args ["authority" ] = authority
81
+ if vscode_tenant_id :
82
+ vscode_args ["tenant_id" ] = vscode_tenant_id
83
+
68
84
authority = normalize_authority (authority ) if authority else get_default_authority ()
69
85
70
86
shared_cache_username = kwargs .pop ("shared_cache_username" , os .environ .get (EnvironmentVariables .AZURE_USERNAME ))
@@ -76,6 +92,11 @@ def __init__(self, **kwargs: "Any") -> None:
76
92
"managed_identity_client_id" , os .environ .get (EnvironmentVariables .AZURE_CLIENT_ID )
77
93
)
78
94
95
+ vscode_tenant_id = kwargs .pop (
96
+ "visual_studio_code_tenant_id" , os .environ .get (EnvironmentVariables .AZURE_TENANT_ID )
97
+ )
98
+
99
+ exclude_visual_studio_code_credential = kwargs .pop ("exclude_visual_studio_code_credential" , True )
79
100
exclude_cli_credential = kwargs .pop ("exclude_cli_credential" , False )
80
101
exclude_environment_credential = kwargs .pop ("exclude_environment_credential" , False )
81
102
exclude_managed_identity_credential = kwargs .pop ("exclude_managed_identity_credential" , False )
@@ -96,6 +117,8 @@ def __init__(self, **kwargs: "Any") -> None:
96
117
credentials .append (shared_cache )
97
118
except Exception as ex : # pylint:disable=broad-except
98
119
_LOGGER .info ("Shared token cache is unavailable: '%s'" , ex )
120
+ if not exclude_visual_studio_code_credential :
121
+ credentials .append (VisualStudioCodeCredential (** vscode_args ))
99
122
if not exclude_cli_credential :
100
123
credentials .append (AzureCliCredential ())
101
124
if not exclude_powershell_credential :
0 commit comments