Skip to content

[Identity] Emit warning in EnvironmentCredential for user/pass #40595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pvaneck
Copy link
Member

@pvaneck pvaneck commented Apr 17, 2025

If UsernamePasswordCredential environment variables are detected in EnvironmentCredential and DefaultAzureCredential, we now ensure that a warning noting its deprecation is emitted with the correct stacklevel that point's to the user's credential instantiation.

Without this, by default, the user won't see the warning emitted in the UsernamePasswordCredential initializer if UsernamePasswordCredential wasn't directly instantiated by the user.

@azure-sdk
Copy link
Collaborator

API change check

API changes are not detected in this pull request.

@pvaneck pvaneck marked this pull request as ready for review April 17, 2025 23:58
@Copilot Copilot AI review requested due to automatic review settings April 17, 2025 23:58
@pvaneck pvaneck requested review from xiangyan99 and a team as code owners April 17, 2025 23:58
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces deprecation warnings for the usage of UsernamePasswordCredential when it is indirectly instantiated through EnvironmentCredential. Key changes include:

  • Adding a new test to verify that the deprecation warning is emitted with the correct stacklevel.
  • Updating the UsernamePasswordCredential to conditionally emit a deprecation warning based on a silencing flag.
  • Emitting a deprecation warning from EnvironmentCredential with an appropriate stacklevel.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
sdk/identity/azure-identity/tests/test_environment_credential.py Adds a test for the deprecation warning behavior.
sdk/identity/azure-identity/azure/identity/aio/_credentials/environment.py Updates docstring to remove legacy authentication method reference.
sdk/identity/azure-identity/azure/identity/_credentials/user_password.py Inserts conditional deprecation warning logic.
sdk/identity/azure-identity/azure/identity/_credentials/environment.py Inserts a deprecation warning emission with dynamic stacklevel.
Comments suppressed due to low confidence (1)

sdk/identity/azure-identity/azure/identity/_credentials/environment.py:104

  • The warning message contains a grammatical error in the phrase 'as is it doesn't support multifactor authentication'. Please update it to 'as it doesn't support multifactor authentication'.
warnings.warn("Environment is configured to use username and password authentication. This authentication method is deprecated, as is it doesn't support multifactor authentication (MFA). For more details, see https://aka.ms/azsdk/identity/mfa.", DeprecationWarning, stacklevel=3 if within_dac.get() else 2)

If UsernamePasswordCredential environment variables are detected in
EnvironmentCredential, a warning noting its deprecation is emitted.

Signed-off-by: Paul Van Eck <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Untriaged
Development

Successfully merging this pull request may close these issues.

2 participants