From 4f258b84436e0f1d751eb21d563cc908b411fcd4 Mon Sep 17 00:00:00 2001
From: Paul Van Eck
Date: Fri, 18 Apr 2025 20:37:44 +0000
Subject: [PATCH] [Identity] Deprecate VisualStudioCodeCredential
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
---
sdk/identity/azure-identity/CHANGELOG.md | 2 ++
sdk/identity/azure-identity/README.md | 16 +---------------
sdk/identity/azure-identity/TROUBLESHOOTING.md | 14 +-------------
.../azure/identity/_credentials/vscode.py | 17 +++++++++++++----
.../azure/identity/aio/_credentials/vscode.py | 8 ++++----
.../tests/test_vscode_credential.py | 6 +++++-
.../tests/test_vscode_credential_async.py | 5 +++++
7 files changed, 31 insertions(+), 37 deletions(-)
diff --git a/sdk/identity/azure-identity/CHANGELOG.md b/sdk/identity/azure-identity/CHANGELOG.md
index fd4b1a95fcb5..8d82f2873902 100644
--- a/sdk/identity/azure-identity/CHANGELOG.md
+++ b/sdk/identity/azure-identity/CHANGELOG.md
@@ -12,6 +12,8 @@
### Other Changes
+- 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))
+
## 1.21.0 (2025-03-11)
### Other Changes
diff --git a/sdk/identity/azure-identity/README.md b/sdk/identity/azure-identity/README.md
index 9858a1329dca..e6b067f64d68 100644
--- a/sdk/identity/azure-identity/README.md
+++ b/sdk/identity/azure-identity/README.md
@@ -27,14 +27,6 @@ pip install azure-identity
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.
-#### Authenticate via Visual Studio Code
-
-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.
-
-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.
-
-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).
-
#### Authenticate via the Azure CLI
`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
This allows for trying all of the developer credentials on your machine while having predictable deployed behavior.
-#### Note about `VisualStudioCodeCredential`
-
-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.
-
## Examples
The following examples are provided:
@@ -233,7 +221,7 @@ As an alternative to specifying the `authority` argument, you can also set the `
AZURE_AUTHORITY_HOST=https://login.partner.microsoftonline.cn
```
-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.
+Not all credentials require this configuration. Credentials that authenticate through a development tool, such as `AzureCliCredential`, use that tool's configuration.
## Credential classes
@@ -277,7 +265,6 @@ Not all credentials require this configuration. Credentials that authenticate th
|[`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)
|[`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)
|[`AzurePowerShellCredential`][powershell_cred_ref]| Authenticates in a development environment with the Azure PowerShell. | [Azure PowerShell authentication](https://learn.microsoft.com/powershell/azure/authenticate-azureps)
-|[`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)
## Environment variables
@@ -402,5 +389,4 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
[token_cred_ref]: https://learn.microsoft.com/python/api/azure-core/azure.core.credentials.tokencredential?view=azure-python
[supports_token_info_ref]: https://learn.microsoft.com/python/api/azure-core/azure.core.credentials.supportstokeninfo?view=azure-python
[troubleshooting_guide]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/identity/azure-identity/TROUBLESHOOTING.md
-[vscode_cred_ref]: https://aka.ms/azsdk/python/identity/vscodecredential
[workload_id_cred_ref]: https://aka.ms/azsdk/python/identity/workloadidentitycredential
diff --git a/sdk/identity/azure-identity/TROUBLESHOOTING.md b/sdk/identity/azure-identity/TROUBLESHOOTING.md
index dcb83c2307ad..7e304bade20a 100644
--- a/sdk/identity/azure-identity/TROUBLESHOOTING.md
+++ b/sdk/identity/azure-identity/TROUBLESHOOTING.md
@@ -20,7 +20,6 @@ This troubleshooting guide covers failure investigation techniques, common error
- [Azure Virtual Machine managed identity](#azure-virtual-machine-managed-identity)
- [Azure App Service and Azure Functions managed identity](#azure-app-service-and-azure-functions-managed-identity)
- [Azure Kubernetes Service managed identity](#azure-kubernetes-service-managed-identity)
-- [Troubleshoot VisualStudioCodeCredential authentication issues](#troubleshoot-visualstudiocodecredential-authentication-issues)
- [Troubleshoot AzureCliCredential authentication issues](#troubleshoot-azureclicredential-authentication-issues)
- [Troubleshoot AzureDeveloperCliCredential authentication issues](#troubleshoot-azuredeveloperclicredential-authentication-issues)
- [Troubleshoot AzurePowerShellCredential authentication issues](#troubleshoot-azurepowershellcredential-authentication-issues)
@@ -86,7 +85,7 @@ See full SDK logging documentation with examples [here][sdk_logging_docs].
| Error |Description| Mitigation |
|---|---|---|
-|`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|- [Enable logging](#logging) to verify the credentials being tried, and get further diagnostic information.
- Consult the troubleshooting guide for underlying credential types for more information.
- [EnvironmentCredential](#troubleshoot-environmentcredential-authentication-issues)
- [ManagedIdentityCredential](#troubleshoot-managedidentitycredential-authentication-issues)
- [VisualStudioCodeCredential](#troubleshoot-visualstudiocodecredential-authentication-issues)
- [AzureCLICredential](#troubleshoot-azureclicredential-authentication-issues)
- [AzurePowershellCredential](#troubleshoot-azurepowershellcredential-authentication-issues)
|
+|`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|- [Enable logging](#logging) to verify the credentials being tried, and get further diagnostic information.
- Consult the troubleshooting guide for underlying credential types for more information.
- [EnvironmentCredential](#troubleshoot-environmentcredential-authentication-issues)
- [ManagedIdentityCredential](#troubleshoot-managedidentitycredential-authentication-issues)
- [AzureCLICredential](#troubleshoot-azureclicredential-authentication-issues)
- [AzurePowershellCredential](#troubleshoot-azurepowershellcredential-authentication-issues)
|
|`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.|- [Enable logging](#logging) to determine which credential in the chain returned the authenticating token.
- 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`.
- 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.
|
## Troubleshoot `EnvironmentCredential` authentication issues
@@ -191,17 +190,6 @@ curl 'http://169.254.169.254/metadata/identity/oauth2/token?resource=https://man
|---|---|---|
|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)).
-## Troubleshoot `VisualStudioCodeCredential` authentication issues
-
-> 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).
-
-`CredentialUnavailableError`
-| Error Message |Description| Mitigation |
-|---|---|---|
-|Failed To Read VS Code Credentials
ORAuthenticate via Azure Tools plugin in VS Code|No Azure account information was found in the VS Code configuration.|- Ensure the [Azure Account plugin](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account) is properly installed
- 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.
- 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.
|
-|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.|
-|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:- AZURE PUBLIC CLOUD - https://login.microsoftonline.com/
- AZURE CHINA - https://login.chinacloudapi.cn/
- AZURE GOVERNMENT - https://login.microsoftonline.us/
|
-
## Troubleshoot `AzureCliCredential` authentication issues
`CredentialUnavailableError`
diff --git a/sdk/identity/azure-identity/azure/identity/_credentials/vscode.py b/sdk/identity/azure-identity/azure/identity/_credentials/vscode.py
index cd5fbd147ab7..79f126064046 100644
--- a/sdk/identity/azure-identity/azure/identity/_credentials/vscode.py
+++ b/sdk/identity/azure-identity/azure/identity/_credentials/vscode.py
@@ -6,6 +6,7 @@
import os
import sys
from typing import cast, Any, Dict, Optional
+import warnings
from azure.core.credentials import AccessToken, TokenRequestOptions, AccessTokenInfo
from azure.core.exceptions import ClientAuthenticationError
@@ -26,6 +27,14 @@
class _VSCodeCredentialBase(abc.ABC):
def __init__(self, **kwargs: Any) -> None:
+ warnings.warn(
+ "This credential is deprecated because the Azure Account extension for Visual Studio Code, which this "
+ "credential relies on, has been deprecated. See the Azure Account extension deprecation notice here: "
+ "https://github.com/microsoft/vscode-azure-account/issues/964. Consider using other developer credentials "
+ "such as AzureCliCredential, AzureDeveloperCliCredential, or AzurePowerShellCredential.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
super(_VSCodeCredentialBase, self).__init__()
user_settings = get_user_settings()
@@ -107,10 +116,10 @@ def _initialize(self, vscode_user_settings: Dict, **kwargs: Any) -> None:
class VisualStudioCodeCredential(_VSCodeCredentialBase, GetTokenMixin):
"""Authenticates as the Azure user signed in to Visual Studio Code via the 'Azure Account' extension.
- It's a `known issue `_ that this credential doesn't
- work with `Azure Account extension `_
- versions newer than **0.9.11**. A long-term fix to this problem is in progress. In the meantime, consider
- authenticating with :class:`AzureCliCredential`.
+ **Deprecated**: This credential is deprecated because the Azure Account extension for Visual Studio Code, which
+ this credential relies on, has been deprecated. See the Azure Account extension deprecation notice here:
+ https://github.com/microsoft/vscode-azure-account/issues/964. Consider using other developer credentials such as
+ AzureCliCredential, AzureDeveloperCliCredential, or AzurePowerShellCredential.
:keyword str authority: Authority of a Microsoft Entra endpoint, for example "login.microsoftonline.com".
This argument is required for a custom cloud and usually unnecessary otherwise. Defaults to the authority
diff --git a/sdk/identity/azure-identity/azure/identity/aio/_credentials/vscode.py b/sdk/identity/azure-identity/azure/identity/aio/_credentials/vscode.py
index 80aa99f764b2..fa5aab6a29a2 100644
--- a/sdk/identity/azure-identity/azure/identity/aio/_credentials/vscode.py
+++ b/sdk/identity/azure-identity/azure/identity/aio/_credentials/vscode.py
@@ -18,10 +18,10 @@
class VisualStudioCodeCredential(_VSCodeCredentialBase, AsyncContextManager, GetTokenMixin):
"""Authenticates as the Azure user signed in to Visual Studio Code via the 'Azure Account' extension.
- It's a `known issue `_ that this credential doesn't
- work with `Azure Account extension `_
- versions newer than **0.9.11**. A long-term fix to this problem is in progress. In the meantime, consider
- authenticating with :class:`AzureCliCredential`.
+ **Deprecated**: This credential is deprecated because the Azure Account extension for Visual Studio Code, which
+ this credential relies on, has been deprecated. See the Azure Account extension deprecation notice here:
+ https://github.com/microsoft/vscode-azure-account/issues/964. Consider using other developer credentials such as
+ AzureCliCredential, AzureDeveloperCliCredential, or AzurePowerShellCredential.
:keyword str authority: Authority of a Microsoft Entra endpoint, for example "login.microsoftonline.com".
This argument is required for a custom cloud and usually unnecessary otherwise. Defaults to the authority
diff --git a/sdk/identity/azure-identity/tests/test_vscode_credential.py b/sdk/identity/azure-identity/tests/test_vscode_credential.py
index 70ce4fd6fe74..4fb643d3ec92 100644
--- a/sdk/identity/azure-identity/tests/test_vscode_credential.py
+++ b/sdk/identity/azure-identity/tests/test_vscode_credential.py
@@ -22,7 +22,6 @@
GET_USER_SETTINGS = VisualStudioCodeCredential.__module__ + ".get_user_settings"
-@pytest.mark.skip(reason="VS code credential is disabled")
def get_credential(user_settings=None, **kwargs):
# defaulting to empty user settings ensures tests work when real user settings are available
with mock.patch(GET_USER_SETTINGS, lambda: user_settings or {}):
@@ -361,3 +360,8 @@ def send(request, **kwargs):
with mock.patch.dict("os.environ", {EnvironmentVariables.AZURE_IDENTITY_DISABLE_MULTITENANTAUTH: "true"}):
token = credential.get_token("scope", tenant_id="un" + expected_tenant)
assert token.token == expected_token
+
+
+def test_deprecation_warning():
+ with pytest.deprecated_call():
+ get_credential()
diff --git a/sdk/identity/azure-identity/tests/test_vscode_credential_async.py b/sdk/identity/azure-identity/tests/test_vscode_credential_async.py
index ce414b6343ac..7e4bf27c671e 100644
--- a/sdk/identity/azure-identity/tests/test_vscode_credential_async.py
+++ b/sdk/identity/azure-identity/tests/test_vscode_credential_async.py
@@ -351,3 +351,8 @@ async def send(request, **kwargs):
with mock.patch.dict("os.environ", {EnvironmentVariables.AZURE_IDENTITY_DISABLE_MULTITENANTAUTH: "true"}):
token = await credential.get_token("scope", tenant_id="un" + expected_tenant)
assert token.token == expected_token
+
+
+def test_deprecation_warning():
+ with pytest.deprecated_call():
+ get_credential()