Skip to content

Commit a287786

Browse files
authored
[Core] Drop old Track 2 SDK authentication support (#29690)
1 parent b46f344 commit a287786

File tree

5 files changed

+8
-42
lines changed

5 files changed

+8
-42
lines changed

src/azure-cli-core/azure/cli/core/auth/adal_authentication.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from knack.log import get_logger
88
from msrestazure.azure_active_directory import MSIAuthentication
99

10-
from .util import _normalize_scopes, scopes_to_resource, AccessToken
10+
from .util import scopes_to_resource, AccessToken
1111

1212
logger = get_logger(__name__)
1313

@@ -39,7 +39,7 @@ def get_token(self, *scopes, **kwargs): # pylint:disable=unused-argument
3939
raise AuthenticationError("VM SSH currently doesn't support managed identity.")
4040

4141
# Use msrestazure to get access token
42-
resource = scopes_to_resource(_normalize_scopes(scopes))
42+
resource = scopes_to_resource(scopes)
4343
if resource:
4444
# If available, use resource provided by SDK
4545
self.resource = resource

src/azure-cli-core/azure/cli/core/auth/credential_adaptor.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from knack.log import get_logger
88
from knack.util import CLIError
99

10-
from .util import resource_to_scopes, _normalize_scopes
10+
from .util import resource_to_scopes
1111

1212
logger = get_logger(__name__)
1313

@@ -62,7 +62,6 @@ def get_token(self, *scopes, **kwargs):
6262
if 'data' in kwargs:
6363
filtered_kwargs['data'] = kwargs['data']
6464

65-
scopes = _normalize_scopes(scopes)
6665
token, _ = self._get_token(scopes, **filtered_kwargs)
6766
return token
6867

src/azure-cli-core/azure/cli/core/auth/tests/test_util.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# pylint: disable=protected-access
77

88
import unittest
9-
from azure.cli.core.auth.util import scopes_to_resource, resource_to_scopes, _normalize_scopes, _generate_login_command
9+
from azure.cli.core.auth.util import scopes_to_resource, resource_to_scopes, _generate_login_command
1010

1111

1212
class TestUtil(unittest.TestCase):
@@ -50,21 +50,6 @@ def test_resource_to_scopes(self):
5050
self.assertEqual(resource_to_scopes('https://managedhsm.azure.com'),
5151
['https://managedhsm.azure.com/.default'])
5252

53-
def test_normalize_scopes(self):
54-
# Test no scopes
55-
self.assertIsNone(_normalize_scopes(()))
56-
self.assertIsNone(_normalize_scopes([]))
57-
self.assertIsNone(_normalize_scopes(None))
58-
59-
# Test multiple scopes, with the first one discarded
60-
scopes = _normalize_scopes(("https://management.core.windows.net//.default",
61-
"https://management.core.chinacloudapi.cn//.default"))
62-
self.assertEqual(list(scopes), ["https://management.core.chinacloudapi.cn//.default"])
63-
64-
# Test single scopes (the correct usage)
65-
scopes = _normalize_scopes(("https://management.core.chinacloudapi.cn//.default",))
66-
self.assertEqual(list(scopes), ["https://management.core.chinacloudapi.cn//.default"])
67-
6853
def test_generate_login_command(self):
6954
# No parameter is given
7055
assert _generate_login_command() == 'az login'

src/azure-cli-core/azure/cli/core/auth/util.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,6 @@ def scopes_to_resource(scopes):
106106
return scope
107107

108108

109-
def _normalize_scopes(scopes):
110-
"""Normalize scopes to workaround some SDK issues."""
111-
112-
# Track 2 SDKs generated before https://github.com/Azure/autorest.python/pull/239 don't maintain
113-
# credential_scopes and call `get_token` with empty scopes.
114-
# As a workaround, return None so that the CLI-managed resource is used.
115-
if not scopes:
116-
logger.debug("No scope is provided by the SDK, use the CLI-managed resource.")
117-
return None
118-
119-
# Track 2 SDKs generated before https://github.com/Azure/autorest.python/pull/745 extend default
120-
# credential_scopes with custom credential_scopes. Instead, credential_scopes should be replaced by
121-
# custom credential_scopes. https://github.com/Azure/azure-sdk-for-python/issues/12947
122-
# As a workaround, remove the first one if there are multiple scopes provided.
123-
if len(scopes) > 1:
124-
logger.debug("Multiple scopes are provided by the SDK, discarding the first one: %s", scopes[0])
125-
return scopes[1:]
126-
127-
return scopes
128-
129-
130109
def check_result(result, **kwargs):
131110
"""Parse the result returned by MSAL:
132111

src/azure-cli-testsdk/azure/cli/testsdk/patches.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ class UserCredentialMock:
6868
def __init__(self, *args, **kwargs):
6969
super().__init__()
7070

71-
def get_token(*args, **kwargs): # pylint: disable=unused-argument
71+
def get_token(self, *scopes, **kwargs): # pylint: disable=unused-argument
72+
# Old Track 2 SDKs are no longer supported. https://github.com/Azure/azure-cli/pull/29690
73+
assert len(scopes) == 1, "'scopes' must contain only one element."
74+
7275
from azure.core.credentials import AccessToken
7376
import time
7477
fake_raw_token = 'top-secret-token-for-you'

0 commit comments

Comments
 (0)