Skip to content

Commit 2e8c9b3

Browse files
committed
ROPC deprecation
1 parent f803aec commit 2e8c9b3

File tree

8 files changed

+23
-4
lines changed

8 files changed

+23
-4
lines changed

msal/__main__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Usage 2: Build an all-in-one executable file for bug bash.
1111
shiv -e msal.__main__._main -o msaltest-on-os-name.pyz .
1212
"""
13-
import base64, getpass, json, logging, sys, os, atexit, msal
13+
import base64, getpass, json, logging, sys, os, atexit, msal, warnings
1414

1515
_token_cache_filename = "msal_cache.bin"
1616
global_cache = msal.SerializableTokenCache()
@@ -149,7 +149,13 @@ def _acquire_token_interactive(app, scopes=None, data=None):
149149
return result
150150

151151
def _acquire_token_by_username_password(app):
152-
"""acquire_token_by_username_password() - See constraints here: https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-authentication-flows#constraints-for-ropc"""
152+
"""
153+
[Deprecated] This API is deprecated and will be removed in a future release. Use a more secure flow instead.
154+
Migration guide: https://aka.ms/msal-ropc-migration
155+
156+
acquire_token_by_username_password() - See constraints here: https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-authentication-flows#constraints-for-ropc
157+
"""
158+
warnings.warn("This API has been deprecated, please use a more secure flow. See https://aka.ms/msal-ropc-migration for migration guidance", DeprecationWarning)
153159
print_json(app.acquire_token_by_username_password(
154160
_input("username: "), getpass.getpass("password: "), scopes=_input_scopes()))
155161

@@ -322,7 +328,6 @@ def _main():
322328
_acquire_pop_token_interactive,
323329
] if isinstance(app, msal.PublicClientApplication) else []
324330
) + [
325-
_acquire_token_by_username_password,
326331
_remove_account,
327332
] + ([
328333
_acquire_token_for_client,

msal/application.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,11 @@ def acquire_token_by_username_password(
18151815
# because this ROPC won't work with MSA account anyway.
18161816
auth_scheme=None,
18171817
**kwargs):
1818-
"""Gets a token for a given resource via user credentials.
1818+
"""
1819+
[Deprecated] This API is deprecated and will be removed in a future release. Use a more secure flow instead.
1820+
Migration guide: https://aka.ms/msal-ropc-migration
1821+
1822+
Gets a token for a given resource via user credentials.
18191823
18201824
See this page for constraints of Username Password Flow.
18211825
https://github.com/AzureAD/microsoft-authentication-library-for-python/wiki/Username-Password-Authentication
@@ -1841,6 +1845,7 @@ def acquire_token_by_username_password(
18411845
- A successful response would contain "access_token" key,
18421846
- an error response would contain "error" and usually "error_description".
18431847
"""
1848+
warnings.warn("This API has been deprecated, please use a more secure flow. See https://aka.ms/msal-ropc-migration for migration guidance", DeprecationWarning)
18441849
claims = _merge_claims_challenge_and_capabilities(
18451850
self._client_capabilities, claims_challenge)
18461851
if self._enable_broker and sys.platform in ("win32", "darwin"):

sample/username_password_sample.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def acquire_and_use_token():
6969
logging.info("No suitable token exists in cache. Let's get a new one from AAD.")
7070
# See this page for constraints of Username Password Flow.
7171
# https://github.com/AzureAD/microsoft-authentication-library-for-python/wiki/Username-Password-Authentication
72+
result = global_app.acquire_token
7273
result = global_app.acquire_token_by_username_password(
7374
os.getenv("USERNAME"), password, scopes=scopes)
7475

tests/broker-test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
4. Run this test by `python broker-test.py` and make sure all the tests passed.
1616
1717
"""
18+
import unittest
1819
import msal
1920
import getpass
2021
import os
@@ -67,6 +68,7 @@ def interactive_and_silent(scopes, auth_scheme, data, expected_token_type):
6768
)
6869
_assert(result, expected_token_type)
6970

71+
@unittest.skip("ROPC API has been deprecated and thus these tests are no longer needed")
7072
def test_broker_username_password(scopes, expected_token_type):
7173
print("Testing broker username password flows by using accounts in local .env")
7274
username = os.getenv("BROKER_TEST_ACCOUNT") or input("Input test account for broker test: ")

tests/test_account_source.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def test_device_flow_and_its_silent_call_should_bypass_broker(self, _, mocked_br
5252
mocked_broker_ats.assert_not_called()
5353
self.assertEqual(result["token_source"], "identity_provider")
5454

55+
@unittest.skip("ROPC API has been deprecated and thus these tests are no longer needed")
5556
def test_ropc_flow_and_its_silent_call_should_invoke_broker(self, _, mocked_broker_ats):
5657
with patch("msal.broker._signin_silently", return_value=dict(TOKEN_RESPONSE, _account_id="placeholder")):
5758
result = self.app.acquire_token_by_username_password(

tests/test_application.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ def mock_post(url, headers=None, *args, **kwargs):
575575
self.assertEqual(result[self.app._TOKEN_SOURCE], self.app._TOKEN_SOURCE_IDP)
576576
self.assertEqual(at, result.get("access_token"))
577577

578+
@unittest.skip("ROPC API has been deprecated and thus these tests are no longer needed")
578579
def test_acquire_token_by_username_password(self):
579580
at = "this is an access token"
580581
def mock_post(url, headers=None, *args, **kwargs):
@@ -706,6 +707,7 @@ def test_organizations_authority_should_emit_warning(self):
706707

707708
@patch(_OIDC_DISCOVERY, new=_OIDC_DISCOVERY_MOCK)
708709
class TestRemoveTokensForClient(unittest.TestCase):
710+
@unittest.skip("ROPC API has been deprecated and thus these tests are no longer needed")
709711
def test_remove_tokens_for_client_should_remove_client_tokens_only(self):
710712
at_for_user = "AT for user"
711713
cca = msal.ConfidentialClientApplication(

tests/test_ccs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def test_acquire_token_silent(self):
6060
mocked_method.call_args[1].get("headers", {}).get('X-AnchorMailbox'),
6161
"CSS routing info should be derived from home_account_id")
6262

63+
@unittest.skip("ROPC API has been deprecated and thus these tests are no longer needed")
6364
def test_acquire_token_by_username_password(self):
6465
app = msal.ClientApplication("client_id")
6566
username = "[email protected]"

tests/test_e2e.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ def _build_app(cls,
197197
enable_broker_on_wsl=_PYMSALRUNTIME_INSTALLED,
198198
)
199199

200+
@unittest.skip("ROPC API has been deprecated and thus these tests are no longer needed")
200201
def _test_username_password(self,
201202
authority=None, client_id=None, username=None, password=None, scope=None,
202203
oidc_authority=None,
@@ -644,6 +645,7 @@ def _test_acquire_token_by_auth_code_flow(
644645
username, result["id_token_claims"]["preferred_username"]))
645646
self.assertCacheWorksForUser(result, scope, username=None)
646647

648+
@unittest.skip("ROPC API has been deprecated and thus these tests are no longer needed")
647649
def _test_acquire_token_obo(self, config_pca, config_cca,
648650
azure_region=None, # Regional endpoint does not really support OBO.
649651
# Here we just test regional apps won't adversely break OBO

0 commit comments

Comments
 (0)