Skip to content

Commit dd36ab2

Browse files
authored
Fix azure.identity.aio.AzureApplicationCredential import (Azure#19961)
1 parent ef54724 commit dd36ab2

File tree

6 files changed

+42
-5
lines changed

6 files changed

+42
-5
lines changed

sdk/identity/azure-identity/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
### Breaking Changes
88

99
### Bugs Fixed
10+
- Fixed import of `azure.identity.aio.AzureApplicationCredential`
11+
([#19943](https://github.com/Azure/azure-sdk-for-python/issues/19943))
1012

1113
### Other Changes
1214
- Reduced redundant `ChainedTokenCredential` and `DefaultAzureCredential`

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from .environment import EnvironmentCredential
1414
from .managed_identity import ManagedIdentityCredential
1515
from .shared_cache import SharedTokenCacheCredential
16-
from .azure_arc import AzureArcCredential
1716
from .azure_cli import AzureCliCredential
1817
from .device_code import DeviceCodeCredential
1918
from .user_password import UsernamePasswordCredential
@@ -23,7 +22,6 @@
2322
__all__ = [
2423
"AuthorizationCodeCredential",
2524
"AzureApplicationCredential",
26-
"AzureArcCredential",
2725
"AzureCliCredential",
2826
"AzurePowerShellCredential",
2927
"CertificateCredential",

sdk/identity/azure-identity/azure/identity/aio/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from ._credentials import (
88
AuthorizationCodeCredential,
9+
AzureApplicationCredential,
910
AzureCliCredential,
1011
AzurePowerShellCredential,
1112
CertificateCredential,
@@ -21,6 +22,7 @@
2122

2223
__all__ = [
2324
"AuthorizationCodeCredential",
25+
"AzureApplicationCredential",
2426
"AzureCliCredential",
2527
"AzurePowerShellCredential",
2628
"CertificateCredential",

sdk/identity/azure-identity/azure/identity/aio/_credentials/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
from .application import AzureApplicationCredential
56
from .authorization_code import AuthorizationCodeCredential
67
from .azure_powershell import AzurePowerShellCredential
78
from .chained import ChainedTokenCredential
@@ -11,14 +12,13 @@
1112
from .certificate import CertificateCredential
1213
from .client_secret import ClientSecretCredential
1314
from .shared_cache import SharedTokenCacheCredential
14-
from .azure_arc import AzureArcCredential
1515
from .azure_cli import AzureCliCredential
1616
from .vscode import VisualStudioCodeCredential
1717

1818

1919
__all__ = [
2020
"AuthorizationCodeCredential",
21-
"AzureArcCredential",
21+
"AzureApplicationCredential",
2222
"AzureCliCredential",
2323
"AzurePowerShellCredential",
2424
"CertificateCredential",

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,25 @@
1515
except ImportError: # python < 3.3
1616
from mock import Mock, patch # type: ignore
1717

18+
from helpers import build_aad_response, get_discovery_response, mock_response
19+
20+
21+
def test_get_token():
22+
expected_token = "***"
23+
24+
def send(request, **_):
25+
parsed = urlparse(request.url)
26+
tenant_id = parsed.path.split("/")[1]
27+
if "/oauth2/v2.0/token" in request.url:
28+
return mock_response(json_payload=build_aad_response(access_token=expected_token))
29+
return get_discovery_response("https://{}/{}".format(parsed.netloc, tenant_id))
30+
31+
with patch.dict("os.environ", {var: "..." for var in EnvironmentVariables.CLIENT_SECRET_VARS}, clear=True):
32+
credential = AzureApplicationCredential(transport=Mock(send=send))
33+
34+
token = credential.get_token("scope")
35+
assert token.token == expected_token
36+
1837

1938
def test_iterates_only_once():
2039
"""When a credential succeeds, AzureApplicationCredential should use that credential thereafter"""

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
from unittest.mock import Mock, patch
77

88
from azure.core.credentials import AccessToken
9-
from azure.identity import AzureApplicationCredential, CredentialUnavailableError
9+
from azure.identity import CredentialUnavailableError
10+
from azure.identity.aio import AzureApplicationCredential
1011
from azure.identity._constants import EnvironmentVariables
1112
import pytest
1213
from six.moves.urllib_parse import urlparse
1314

15+
from helpers import build_aad_response, mock_response
1416
from helpers_async import get_completed_future
1517

1618

@@ -73,6 +75,20 @@ def test_initialization(mock_credential, expect_argument):
7375
test_initialization(mock_credential, expect_argument=False)
7476

7577

78+
@pytest.mark.asyncio
79+
async def test_get_token():
80+
expected_token = "***"
81+
82+
async def send(request, **_):
83+
return mock_response(json_payload=build_aad_response(access_token=expected_token))
84+
85+
with patch.dict("os.environ", {var: "..." for var in EnvironmentVariables.CLIENT_SECRET_VARS}, clear=True):
86+
credential = AzureApplicationCredential(transport=Mock(send=send))
87+
88+
token = await credential.get_token("scope")
89+
assert token.token == expected_token
90+
91+
7692
def test_managed_identity_client_id():
7793
"""the credential should accept a user-assigned managed identity's client ID by kwarg or environment variable"""
7894

0 commit comments

Comments
 (0)