Skip to content

Commit 9da43f7

Browse files
authored
[Identity] Deprecate UsernamePasswordCredential (Azure#39785)
Multifactor authentication will be required on Azure, and this credential doesn't support MFA. Phasing this out. Signed-off-by: Paul Van Eck <[email protected]>
1 parent 9fb3764 commit 9da43f7

File tree

7 files changed

+27
-7
lines changed

7 files changed

+27
-7
lines changed

sdk/identity/azure-identity/CHANGELOG.md

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

1111
### Other Changes
1212

13+
- Deprecated `UsernamePasswordCredential`, as it doesn't support multifactor authentication (MFA). MFA will soon be enforced on all Microsoft Entra tenants. For more details, see [Planning for mandatory MFA](https://aka.ms/mfaforazure). ([#39785](https://github.com/Azure/azure-sdk-for-python/pull/39785))
14+
1315
## 1.20.0 (2025-02-11)
1416

1517
### Features Added

sdk/identity/azure-identity/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ Not all credentials require this configuration. Credentials that authenticate th
269269
|[`DeviceCodeCredential`][device_code_cred_ref]| Interactively authenticates a user on devices with limited UI. | [Device code authentication](https://learn.microsoft.com/entra/identity-platform/v2-oauth2-device-code)|
270270
|[`InteractiveBrowserCredential`][interactive_cred_ref]| Interactively authenticates a user with the default system browser. | [OAuth2 authentication code](https://learn.microsoft.com/entra/identity-platform/v2-oauth2-auth-code-flow)| `InteractiveBrowserCredential` doesn't support GitHub Codespaces. As a workaround, use [`DeviceCodeCredential`][device_code_cred_ref].
271271
|[`OnBehalfOfCredential`][obo_cred_ref]| Propagates the delegated user identity and permissions through the request chain. | [On-behalf-of authentication](https://learn.microsoft.com/entra/identity-platform/v2-oauth2-on-behalf-of-flow)|
272-
|[`UsernamePasswordCredential`][userpass_cred_ref]| Authenticates a user with a username and password (doesn't support multifactor authentication). | [Username + password authentication](https://learn.microsoft.com/entra/identity-platform/v2-oauth-ropc)|
272+
|[`UsernamePasswordCredential`][userpass_cred_ref]| **Deprecated** - Authenticates a user with a username and password (doesn't support multifactor authentication). | [Username + password authentication](https://learn.microsoft.com/entra/identity-platform/v2-oauth-ropc)|
273273

274274
### Authenticate via development tools
275275

@@ -305,6 +305,8 @@ variables:
305305

306306
### Username and password
307307

308+
> **Warning**: Username and password authentication doesn't support multifactor authentication (MFA) and is **deprecated**. For more details, see [Planning for mandatory MFA](https://aka.ms/azsdk/identity/mfa).
309+
308310
|Variable name|Value
309311
|-|-
310312
|`AZURE_CLIENT_ID`|ID of a Microsoft Entra application

sdk/identity/azure-identity/TOKEN_CACHING.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ClientSecretCredential(
5252

5353
#### Persist user authentication record
5454

55-
When authenticating a user via `InteractiveBrowserCredential`, `DeviceCodeCredential`, or `UsernamePasswordCredential`, an `AuthenticationRecord` can be persisted as well. The authentication record is:
55+
When authenticating a user via `InteractiveBrowserCredential` or `DeviceCodeCredential`, an `AuthenticationRecord` can be persisted as well. The authentication record is:
5656

5757
- Returned from the `authenticate` API and contains data identifying an authenticated account.
5858
- Needed to identify the appropriate entry in the persisted token cache to silently authenticate on subsequent executions.
@@ -68,7 +68,7 @@ record_json = record.serialize()
6868

6969
#### Silently authenticating a user with AuthenticationRecord and TokenCachePersistenceOptions
7070

71-
Once an app has configured an `InteractiveBrowserCredential`, `DeviceCodeCredential`, or `UsernamePasswordCredential` to persist token data and an `AuthenticationRecord`, it's possible to silently authenticate. This example demonstrates an app setting the `TokenCachePersistenceOptions` and retrieving an `AuthenticationRecord` from the local file system to create an `InteractiveBrowserCredential` capable of silent authentication:
71+
Once an app has configured an `InteractiveBrowserCredential` or `DeviceCodeCredential`, to persist token data and an `AuthenticationRecord`, it's possible to silently authenticate. This example demonstrates an app setting the `TokenCachePersistenceOptions` and retrieving an `AuthenticationRecord` from the local file system to create an `InteractiveBrowserCredential` capable of silent authentication:
7272

7373
```python
7474
deserialized_record = AuthenticationRecord.deserialize(record_json)
@@ -101,5 +101,4 @@ The following table indicates the state of in-memory and persistent caching in e
101101
| `InteractiveBrowserCredential` | Supported | Supported |
102102
| `ManagedIdentityCredential` | Supported | Not Supported |
103103
| `OnBehalfOfCredential` | Supported | Supported |
104-
| `UsernamePasswordCredential` | Supported | Supported |
105104
| `WorkloadIdentityCredential` | Supported | Not Supported |

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class EnvironmentCredential:
4646
when no value is given.
4747
4848
User with username and password:
49+
**Deprecated**: Username and password authentication doesn't support multifactor authentication (MFA).
50+
For more details on Microsoft Entra MFA enforcement, see https://aka.ms/azsdk/identity/mfa.
51+
4952
- **AZURE_CLIENT_ID**: the application's client ID
5053
- **AZURE_USERNAME**: a username (usually an email address)
5154
- **AZURE_PASSWORD**: that user's password

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
# Licensed under the MIT License.
44
# ------------------------------------
55
from typing import Any, Dict
6+
import warnings
67

78
from .._internal import InteractiveCredential, wrap_exceptions
89

910

1011
class UsernamePasswordCredential(InteractiveCredential):
1112
"""Authenticates a user with a username and password.
1213
14+
**Deprecated**: This credential doesn't support multifactor authentication (MFA).
15+
For more details on Microsoft Entra MFA enforcement, see https://aka.ms/azsdk/identity/mfa.
16+
1317
In general, Microsoft doesn't recommend this kind of authentication, because it's less secure than other
1418
authentication flows.
1519
@@ -59,6 +63,12 @@ class UsernamePasswordCredential(InteractiveCredential):
5963
"""
6064

6165
def __init__(self, client_id: str, username: str, password: str, **kwargs: Any) -> None:
66+
warnings.warn(
67+
f"{self.__class__.__name__} is deprecated, as is it doesn't support multifactor "
68+
"authentication (MFA). For more details, see https://aka.ms/azsdk/identity/mfa.",
69+
category=DeprecationWarning,
70+
stacklevel=2,
71+
)
6272
# The base class will accept an AuthenticationRecord, allowing this credential to authenticate silently the
6373
# first time it's asked for a token. However, we want to ensure this first authentication is not silent, to
6474
# validate the given password. This class therefore doesn't document the authentication_record argument, and we

sdk/identity/azure-identity/samples/azure-aad-auth-with-redis-py.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ if __name__ == '__main__':
8282
- [Client Certificate Credential](https://aka.ms/azsdk/python/identity/certificatecredential)
8383
- [Client Secret Credential](https://aka.ms/azsdk/python/identity/clientsecretcredential)
8484
- [Managed Identity Credential](https://aka.ms/azsdk/python/identity/managedidentitycredential)
85-
- [Username Password Credential](https://aka.ms/azsdk/python/identity/usernamepasswordcredential)
8685
- [Azure CLI Credential](https://aka.ms/azsdk/python/identity/azclicredential)
8786
- [Interactive Browser Credential](https://aka.ms/azsdk/python/identity/interactivebrowsercredential)
8887
- [Device Code Credential](https://aka.ms/azsdk/python/identity/devicecodecredential)
@@ -188,7 +187,7 @@ To mitigate this error, navigate to your Azure Cache for Redis resource in the A
188187

189188
##### Managed Identity not working from Local Development Machine
190189

191-
Managed identity does not work from a local development machine. To use managed identity, your code must be running
192-
in an Azure VM (or another type of resource in Azure). To run locally with Entra ID authentication, you'll need to
190+
Managed identity does not work from a local development machine. To use managed identity, your code must be running
191+
in an Azure VM (or another type of resource in Azure). To run locally with Entra ID authentication, you'll need to
193192
use a service principal or user account. This is a common source of confusion, so ensure that when developing locally,
194193
you configure your application to use a service principal or user credentials for authentication.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,8 @@ def test_claims_challenge(get_token_method):
229229
assert msal_app.acquire_token_silent_with_error.call_count == 1
230230
args, kwargs = msal_app.acquire_token_silent_with_error.call_args
231231
assert kwargs["claims_challenge"] == expected_claims
232+
233+
234+
def test_deprecation_warning():
235+
with pytest.deprecated_call():
236+
UsernamePasswordCredential("client-id", "username", "password")

0 commit comments

Comments
 (0)