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/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Release History

### 1.1.0b1 Unreleased
- Constructing `DefaultAzureCredential` no longer raises `ImportError` on Python
3.8 on Windows ([8294](https://github.com/Azure/azure-sdk-for-python/pull/8294))


### 2019-11-05 1.0.1
Expand Down
16 changes: 11 additions & 5 deletions sdk/identity/azure-identity/azure/identity/_credentials/default.py
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.
# ------------------------------------
import logging
import os

from .._constants import EnvironmentVariables
Expand All @@ -10,6 +11,8 @@
from .managed_identity import ManagedIdentityCredential
from .user import SharedTokenCacheCredential

_LOGGER = logging.getLogger(__name__)


class DefaultAzureCredential(ChainedTokenCredential):
"""A default credential capable of handling most Azure SDK authentication scenarios.
Expand All @@ -35,10 +38,13 @@ def __init__(self, **kwargs):

# SharedTokenCacheCredential is part of the default only on supported platforms.
if SharedTokenCacheCredential.supported():
credentials.append(
SharedTokenCacheCredential(
username=os.environ.get(EnvironmentVariables.AZURE_USERNAME), authority=authority, **kwargs
)
)
try:
# username is only required to disambiguate, when the cache contains tokens for multiple identities
username = os.environ.get(EnvironmentVariables.AZURE_USERNAME)
shared_cache = SharedTokenCacheCredential(username=username, authority=authority, **kwargs)
credentials.append(shared_cache)
except Exception as ex: # pylint:disable=broad-except
# transitive dependency pywin32 doesn't support 3.8 (https://github.com/mhammond/pywin32/issues/1431)
_LOGGER.info("Shared token cache is unavailable: '%s'", ex)

super(DefaultAzureCredential, self).__init__(*credentials)
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.
# ------------------------------------
import logging
import os

from ..._constants import EnvironmentVariables
Expand All @@ -10,6 +11,8 @@
from .managed_identity import ManagedIdentityCredential
from .user import SharedTokenCacheCredential

_LOGGER = logging.getLogger(__name__)


class DefaultAzureCredential(ChainedTokenCredential):
"""A default credential capable of handling most Azure SDK authentication scenarios.
Expand All @@ -35,10 +38,13 @@ def __init__(self, **kwargs):

# SharedTokenCacheCredential is part of the default only on supported platforms.
if SharedTokenCacheCredential.supported():
credentials.append(
SharedTokenCacheCredential(
username=os.environ.get(EnvironmentVariables.AZURE_USERNAME), authority=authority, **kwargs
)
)
try:
# username is only required to disambiguate, when the cache contains tokens for multiple identities
username = os.environ.get(EnvironmentVariables.AZURE_USERNAME)
shared_cache = SharedTokenCacheCredential(username=username, authority=authority, **kwargs)
credentials.append(shared_cache)
except Exception as ex: # pylint:disable=broad-except
# transitive dependency pywin32 doesn't support 3.8 (https://github.com/mhammond/pywin32/issues/1431)
_LOGGER.info("Shared token cache is unavailable: '%s'", ex)

super().__init__(*credentials)