Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/identity/azure-identity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
### Breaking Changes

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

### Other Changes
- Reduced redundant `ChainedTokenCredential` and `DefaultAzureCredential`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from .environment import EnvironmentCredential
from .managed_identity import ManagedIdentityCredential
from .shared_cache import SharedTokenCacheCredential
from .azure_arc import AzureArcCredential
from .azure_cli import AzureCliCredential
from .device_code import DeviceCodeCredential
from .user_password import UsernamePasswordCredential
Expand All @@ -23,7 +22,6 @@
__all__ = [
"AuthorizationCodeCredential",
"AzureApplicationCredential",
"AzureArcCredential",
"AzureCliCredential",
"AzurePowerShellCredential",
"CertificateCredential",
Expand Down
2 changes: 2 additions & 0 deletions sdk/identity/azure-identity/azure/identity/aio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from ._credentials import (
AuthorizationCodeCredential,
AzureApplicationCredential,
AzureCliCredential,
AzurePowerShellCredential,
CertificateCredential,
Expand All @@ -21,6 +22,7 @@

__all__ = [
"AuthorizationCodeCredential",
"AzureApplicationCredential",
"AzureCliCredential",
"AzurePowerShellCredential",
"CertificateCredential",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from .application import AzureApplicationCredential
from .authorization_code import AuthorizationCodeCredential
from .azure_powershell import AzurePowerShellCredential
from .chained import ChainedTokenCredential
Expand All @@ -11,14 +12,13 @@
from .certificate import CertificateCredential
from .client_secret import ClientSecretCredential
from .shared_cache import SharedTokenCacheCredential
from .azure_arc import AzureArcCredential
from .azure_cli import AzureCliCredential
from .vscode import VisualStudioCodeCredential


__all__ = [
"AuthorizationCodeCredential",
"AzureArcCredential",
"AzureApplicationCredential",
"AzureCliCredential",
"AzurePowerShellCredential",
"CertificateCredential",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@
except ImportError: # python < 3.3
from mock import Mock, patch # type: ignore

from helpers import build_aad_response, get_discovery_response, mock_response


def test_get_token():
expected_token = "***"

def send(request, **_):
parsed = urlparse(request.url)
tenant_id = parsed.path.split("/")[1]
if "/oauth2/v2.0/token" in request.url:
return mock_response(json_payload=build_aad_response(access_token=expected_token))
return get_discovery_response("https://{}/{}".format(parsed.netloc, tenant_id))

with patch.dict("os.environ", {var: "..." for var in EnvironmentVariables.CLIENT_SECRET_VARS}, clear=True):
credential = AzureApplicationCredential(transport=Mock(send=send))

token = credential.get_token("scope")
assert token.token == expected_token


def test_iterates_only_once():
"""When a credential succeeds, AzureApplicationCredential should use that credential thereafter"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
from unittest.mock import Mock, patch

from azure.core.credentials import AccessToken
from azure.identity import AzureApplicationCredential, CredentialUnavailableError
from azure.identity import CredentialUnavailableError
from azure.identity.aio import AzureApplicationCredential
from azure.identity._constants import EnvironmentVariables
import pytest
from six.moves.urllib_parse import urlparse

from helpers import build_aad_response, mock_response
from helpers_async import get_completed_future


Expand Down Expand Up @@ -73,6 +75,20 @@ def test_initialization(mock_credential, expect_argument):
test_initialization(mock_credential, expect_argument=False)


@pytest.mark.asyncio
async def test_get_token():
expected_token = "***"

async def send(request, **_):
return mock_response(json_payload=build_aad_response(access_token=expected_token))

with patch.dict("os.environ", {var: "..." for var in EnvironmentVariables.CLIENT_SECRET_VARS}, clear=True):
credential = AzureApplicationCredential(transport=Mock(send=send))

token = await credential.get_token("scope")
assert token.token == expected_token


def test_managed_identity_client_id():
"""the credential should accept a user-assigned managed identity's client ID by kwarg or environment variable"""

Expand Down