Skip to content

Commit 4d0a196

Browse files
authored
[Identity] Deprecate VisualStudioCodeCredential (#40613)
This credential is deprecated because the Azure Account extension for Visual Studio Code, which this credential relies on, has been deprecated. Signed-off-by: Paul Van Eck <[email protected]>
1 parent 1ad3542 commit 4d0a196

File tree

7 files changed

+31
-37
lines changed

7 files changed

+31
-37
lines changed

sdk/identity/azure-identity/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
### Other Changes
1414

15+
- Deprecated `VisualStudioCodeCredential` as the VS Code Azure Account extension on which this credential depends on has been deprecated. See the Azure Account extension [deprecation notice](https://github.com/microsoft/vscode-azure-account/issues/964). ([#40613](https://github.com/Azure/azure-sdk-for-python/pull/40613))
16+
1517
## 1.21.0 (2025-03-11)
1618

1719
### Other Changes

sdk/identity/azure-identity/README.md

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ pip install azure-identity
2727

2828
When debugging and executing code locally, it's typical for developers to use their own accounts for authenticating calls to Azure services. The Azure Identity library supports authenticating through developer tools to simplify local development.
2929

30-
#### Authenticate via Visual Studio Code
31-
32-
Developers using Visual Studio Code can use the [Azure Account extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account) to authenticate via the editor. Apps using `DefaultAzureCredential` or `VisualStudioCodeCredential` can then use this account to authenticate calls in their app when running locally.
33-
34-
To authenticate in Visual Studio Code, ensure the Azure Account extension is installed. Once installed, open the **Command Palette** and run the **Azure: Sign In** command.
35-
36-
It's a [known issue](https://github.com/Azure/azure-sdk-for-python/issues/23249) that `VisualStudioCodeCredential` doesn't work with [Azure Account extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account) versions newer than **0.9.11**. A long-term fix to this problem is in progress. In the meantime, consider [authenticating via the Azure CLI](#authenticate-via-the-azure-cli).
37-
3830
#### Authenticate via the Azure CLI
3931

4032
`DefaultAzureCredential` and `AzureCliCredential` can authenticate as the user signed in to the [Azure CLI][azure_cli]. To sign in to the Azure CLI, run `az login`. On a system with a default web browser, the Azure CLI launches the browser to authenticate a user.
@@ -67,10 +59,6 @@ As of version 1.14.0, `DefaultAzureCredential` attempts to authenticate with all
6759

6860
This allows for trying all of the developer credentials on your machine while having predictable deployed behavior.
6961

70-
#### Note about `VisualStudioCodeCredential`
71-
72-
Due to a [known issue](https://github.com/Azure/azure-sdk-for-python/issues/23249), `VisualStudioCodeCredential` has been removed from the `DefaultAzureCredential` token chain. When the issue is resolved in a future release, this change will be reverted.
73-
7462
## Examples
7563

7664
The following examples are provided:
@@ -233,7 +221,7 @@ As an alternative to specifying the `authority` argument, you can also set the `
233221
AZURE_AUTHORITY_HOST=https://login.partner.microsoftonline.cn
234222
```
235223

236-
Not all credentials require this configuration. Credentials that authenticate through a development tool, such as `AzureCliCredential`, use that tool's configuration. Similarly, `VisualStudioCodeCredential` accepts an `authority` argument but defaults to the authority matching VS Code's "Azure: Cloud" setting.
224+
Not all credentials require this configuration. Credentials that authenticate through a development tool, such as `AzureCliCredential`, use that tool's configuration.
237225

238226
## Credential classes
239227

@@ -277,7 +265,6 @@ Not all credentials require this configuration. Credentials that authenticate th
277265
|[`AzureCliCredential`][cli_cred_ref]| Authenticates in a development environment with the Azure CLI. | [Azure CLI authentication](https://learn.microsoft.com/cli/azure/authenticate-azure-cli)
278266
|[`AzureDeveloperCliCredential`][azd_cli_cred_ref]| Authenticates in a development environment with the Azure Developer CLI. | [Azure Developer CLI Reference](https://learn.microsoft.com/azure/developer/azure-developer-cli/reference)
279267
|[`AzurePowerShellCredential`][powershell_cred_ref]| Authenticates in a development environment with the Azure PowerShell. | [Azure PowerShell authentication](https://learn.microsoft.com/powershell/azure/authenticate-azureps)
280-
|[`VisualStudioCodeCredential`][vscode_cred_ref]| Authenticates as the user signed in to the Visual Studio Code Azure Account extension. | [VS Code Azure Account extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account)
281268

282269
## Environment variables
283270

@@ -402,5 +389,4 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
402389
[token_cred_ref]: https://learn.microsoft.com/python/api/azure-core/azure.core.credentials.tokencredential?view=azure-python
403390
[supports_token_info_ref]: https://learn.microsoft.com/python/api/azure-core/azure.core.credentials.supportstokeninfo?view=azure-python
404391
[troubleshooting_guide]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/identity/azure-identity/TROUBLESHOOTING.md
405-
[vscode_cred_ref]: https://aka.ms/azsdk/python/identity/vscodecredential
406392
[workload_id_cred_ref]: https://aka.ms/azsdk/python/identity/workloadidentitycredential

sdk/identity/azure-identity/TROUBLESHOOTING.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ This troubleshooting guide covers failure investigation techniques, common error
2020
- [Azure Virtual Machine managed identity](#azure-virtual-machine-managed-identity)
2121
- [Azure App Service and Azure Functions managed identity](#azure-app-service-and-azure-functions-managed-identity)
2222
- [Azure Kubernetes Service managed identity](#azure-kubernetes-service-managed-identity)
23-
- [Troubleshoot VisualStudioCodeCredential authentication issues](#troubleshoot-visualstudiocodecredential-authentication-issues)
2423
- [Troubleshoot AzureCliCredential authentication issues](#troubleshoot-azureclicredential-authentication-issues)
2524
- [Troubleshoot AzureDeveloperCliCredential authentication issues](#troubleshoot-azuredeveloperclicredential-authentication-issues)
2625
- [Troubleshoot AzurePowerShellCredential authentication issues](#troubleshoot-azurepowershellcredential-authentication-issues)
@@ -86,7 +85,7 @@ See full SDK logging documentation with examples [here][sdk_logging_docs].
8685

8786
| Error |Description| Mitigation |
8887
|---|---|---|
89-
|`CredentialUnavailableError` raised with message. "DefaultAzureCredential failed to retrieve a token from the included credentials."|All credentials in the `DefaultAzureCredential` chain failed to retrieve a token, each raising a `CredentialUnavailableError` themselves|<ul><li>[Enable logging](#logging) to verify the credentials being tried, and get further diagnostic information.</li><li>Consult the troubleshooting guide for underlying credential types for more information.</li><ul><li>[EnvironmentCredential](#troubleshoot-environmentcredential-authentication-issues)</li><li>[ManagedIdentityCredential](#troubleshoot-managedidentitycredential-authentication-issues)</li><li>[VisualStudioCodeCredential](#troubleshoot-visualstudiocodecredential-authentication-issues)</li><li>[AzureCLICredential](#troubleshoot-azureclicredential-authentication-issues)</li><li>[AzurePowershellCredential](#troubleshoot-azurepowershellcredential-authentication-issues)</li></ul>|
88+
|`CredentialUnavailableError` raised with message. "DefaultAzureCredential failed to retrieve a token from the included credentials."|All credentials in the `DefaultAzureCredential` chain failed to retrieve a token, each raising a `CredentialUnavailableError` themselves|<ul><li>[Enable logging](#logging) to verify the credentials being tried, and get further diagnostic information.</li><li>Consult the troubleshooting guide for underlying credential types for more information.</li><ul><li>[EnvironmentCredential](#troubleshoot-environmentcredential-authentication-issues)</li><li>[ManagedIdentityCredential](#troubleshoot-managedidentitycredential-authentication-issues)</li><li>[AzureCLICredential](#troubleshoot-azureclicredential-authentication-issues)</li><li>[AzurePowershellCredential](#troubleshoot-azurepowershellcredential-authentication-issues)</li></ul>|
9089
|`ClientAuthenticationError` raised from the client with a status code of 401 or 403|Authentication succeeded but the authorizing Azure service responded with a 401 (Authenticate), or 403 (Forbidden) status code. This can often be caused by the `DefaultAzureCredential` authenticating an account other than the intended one.|<ul><li>[Enable logging](#logging) to determine which credential in the chain returned the authenticating token.</li><li>In the case a credential other than the expected is returning a token, bypass this by either signing out of the corresponding development tool, or excluding the credential with an `exclude_xxx_credential` keyword argument when creating `DefaultAzureCredential`.</li><li>Consult the [troubleshooting guide](#troubleshoot-multi-tenant-authentication-issues) for multi-tenant authentication issues if an error is encountered stating the current credential is not configured to acquire tokens for a tenant.</li></ul>|
9190

9291
## Troubleshoot `EnvironmentCredential` authentication issues
@@ -191,17 +190,6 @@ curl 'http://169.254.169.254/metadata/identity/oauth2/token?resource=https://man
191190
|---|---|---|
192191
|No managed identity endpoint found|The application attempted to authenticate before an identity was assigned to its pod|Verify the pod is labeled correctly. This also occurs when a correctly labeled pod authenticates before the identity is ready. To prevent initialization races, configure NMI to set the Retry-After header in its responses (see [Pod Identity documentation](https://azure.github.io/aad-pod-identity/docs/configure/feature_flags/#set-retry-after-header-in-nmi-response)).
193192

194-
## Troubleshoot `VisualStudioCodeCredential` authentication issues
195-
196-
> It's a [known issue](https://github.com/Azure/azure-sdk-for-python/issues/23249) that `VisualStudioCodeCredential` doesn't work with [Azure Account extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account) versions newer than **0.9.11**. A long-term fix to this problem is in progress. In the meantime, consider [authenticating via the Azure CLI](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/identity/azure-identity/README.md#authenticate-via-the-azure-cli).
197-
198-
`CredentialUnavailableError`
199-
| Error Message |Description| Mitigation |
200-
|---|---|---|
201-
|Failed To Read VS Code Credentials</p></p>OR</p>Authenticate via Azure Tools plugin in VS Code|No Azure account information was found in the VS Code configuration.|<ul><li>Ensure the [Azure Account plugin](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account) is properly installed</li><li>Use **View > Command Palette** to execute the **Azure: Sign In** command. This command opens a browser window and displays a page that allows you to sign in to Azure.</li><li>If you already had the Azure Account extension installed and had logged in to your account, try logging out and logging in again as that will repopulate the cache and potentially mitigate the error you're getting.</li></ul>|
202-
|MSAL Interaction Required Error|The `VisualStudioCodeCredential` was able to read the cached credentials from the cache but the cached token is likely expired.|Log into the Azure Account extension via **View > Command Palette** to execute the **Azure: Sign In** command in the VS Code IDE.|
203-
|ADFS tenant not supported|ADFS tenants are not currently supported by Visual Stuido `Azure Service Authentication`.|Use credentials from a supported cloud when authenticating with Visual Studio. The supported clouds are:</p><ul><li>AZURE PUBLIC CLOUD - https://login.microsoftonline.com/</li><li>AZURE CHINA - https://login.chinacloudapi.cn/</li><li>AZURE GOVERNMENT - https://login.microsoftonline.us/</li></ul>|
204-
205193
## Troubleshoot `AzureCliCredential` authentication issues
206194

207195
`CredentialUnavailableError`

sdk/identity/azure-identity/azure/identity/_credentials/vscode.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import sys
88
from typing import cast, Any, Dict, Optional
9+
import warnings
910

1011
from azure.core.credentials import AccessToken, TokenRequestOptions, AccessTokenInfo
1112
from azure.core.exceptions import ClientAuthenticationError
@@ -26,6 +27,14 @@
2627

2728
class _VSCodeCredentialBase(abc.ABC):
2829
def __init__(self, **kwargs: Any) -> None:
30+
warnings.warn(
31+
"This credential is deprecated because the Azure Account extension for Visual Studio Code, which this "
32+
"credential relies on, has been deprecated. See the Azure Account extension deprecation notice here: "
33+
"https://github.com/microsoft/vscode-azure-account/issues/964. Consider using other developer credentials "
34+
"such as AzureCliCredential, AzureDeveloperCliCredential, or AzurePowerShellCredential.",
35+
DeprecationWarning,
36+
stacklevel=2,
37+
)
2938
super(_VSCodeCredentialBase, self).__init__()
3039

3140
user_settings = get_user_settings()
@@ -107,10 +116,10 @@ def _initialize(self, vscode_user_settings: Dict, **kwargs: Any) -> None:
107116
class VisualStudioCodeCredential(_VSCodeCredentialBase, GetTokenMixin):
108117
"""Authenticates as the Azure user signed in to Visual Studio Code via the 'Azure Account' extension.
109118
110-
It's a `known issue <https://github.com/Azure/azure-sdk-for-python/issues/23249>`_ that this credential doesn't
111-
work with `Azure Account extension <https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account>`_
112-
versions newer than **0.9.11**. A long-term fix to this problem is in progress. In the meantime, consider
113-
authenticating with :class:`AzureCliCredential`.
119+
**Deprecated**: This credential is deprecated because the Azure Account extension for Visual Studio Code, which
120+
this credential relies on, has been deprecated. See the Azure Account extension deprecation notice here:
121+
https://github.com/microsoft/vscode-azure-account/issues/964. Consider using other developer credentials such as
122+
AzureCliCredential, AzureDeveloperCliCredential, or AzurePowerShellCredential.
114123
115124
:keyword str authority: Authority of a Microsoft Entra endpoint, for example "login.microsoftonline.com".
116125
This argument is required for a custom cloud and usually unnecessary otherwise. Defaults to the authority

sdk/identity/azure-identity/azure/identity/aio/_credentials/vscode.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
class VisualStudioCodeCredential(_VSCodeCredentialBase, AsyncContextManager, GetTokenMixin):
1919
"""Authenticates as the Azure user signed in to Visual Studio Code via the 'Azure Account' extension.
2020
21-
It's a `known issue <https://github.com/Azure/azure-sdk-for-python/issues/23249>`_ that this credential doesn't
22-
work with `Azure Account extension <https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account>`_
23-
versions newer than **0.9.11**. A long-term fix to this problem is in progress. In the meantime, consider
24-
authenticating with :class:`AzureCliCredential`.
21+
**Deprecated**: This credential is deprecated because the Azure Account extension for Visual Studio Code, which
22+
this credential relies on, has been deprecated. See the Azure Account extension deprecation notice here:
23+
https://github.com/microsoft/vscode-azure-account/issues/964. Consider using other developer credentials such as
24+
AzureCliCredential, AzureDeveloperCliCredential, or AzurePowerShellCredential.
2525
2626
:keyword str authority: Authority of a Microsoft Entra endpoint, for example "login.microsoftonline.com".
2727
This argument is required for a custom cloud and usually unnecessary otherwise. Defaults to the authority

sdk/identity/azure-identity/tests/test_vscode_credential.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
GET_USER_SETTINGS = VisualStudioCodeCredential.__module__ + ".get_user_settings"
2323

2424

25-
@pytest.mark.skip(reason="VS code credential is disabled")
2625
def get_credential(user_settings=None, **kwargs):
2726
# defaulting to empty user settings ensures tests work when real user settings are available
2827
with mock.patch(GET_USER_SETTINGS, lambda: user_settings or {}):
@@ -361,3 +360,8 @@ def send(request, **kwargs):
361360
with mock.patch.dict("os.environ", {EnvironmentVariables.AZURE_IDENTITY_DISABLE_MULTITENANTAUTH: "true"}):
362361
token = credential.get_token("scope", tenant_id="un" + expected_tenant)
363362
assert token.token == expected_token
363+
364+
365+
def test_deprecation_warning():
366+
with pytest.deprecated_call():
367+
get_credential()

sdk/identity/azure-identity/tests/test_vscode_credential_async.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,8 @@ async def send(request, **kwargs):
351351
with mock.patch.dict("os.environ", {EnvironmentVariables.AZURE_IDENTITY_DISABLE_MULTITENANTAUTH: "true"}):
352352
token = await credential.get_token("scope", tenant_id="un" + expected_tenant)
353353
assert token.token == expected_token
354+
355+
356+
def test_deprecation_warning():
357+
with pytest.deprecated_call():
358+
get_credential()

0 commit comments

Comments
 (0)