Skip to content

Commit f936ea4

Browse files
albertoforiCustardTart32
authored andcommitted
[App Config] az appconfig: Add support for custom token audience to --auth-mode login parameter (Azure#30739)
1 parent 64dffa4 commit f936ea4

File tree

3 files changed

+12878
-7703
lines changed

3 files changed

+12878
-7703
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
# pylint: disable=too-few-public-methods
7+
from azure.cli.core.auth.util import resource_to_scopes
8+
9+
10+
# This class is used to pass in custom token audience that will be respected by the SDK.
11+
# Users can configure an audience based on their cloud.
12+
class AppConfigurationCliCredential:
13+
14+
def __init__(self, credential, resource: str = None):
15+
self._impl = credential
16+
self._resource = resource
17+
18+
def get_token(self, *scopes, **kwargs):
19+
20+
if self._resource is not None:
21+
scopes = resource_to_scopes(self._resource)
22+
23+
return self._impl.get_token(*scopes, **kwargs)

src/azure-cli/azure/cli/command_modules/appconfig/_utils.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,18 @@ def get_appconfig_data_client(cmd, name, connection_string, auth_mode, endpoint)
177177
raise CLIError(str(ex) + "\nYou may be able to resolve this issue by providing App Configuration endpoint instead of name.")
178178

179179
from azure.cli.core._profile import Profile
180+
from azure.cli.core.cloud import get_active_cloud
181+
from ._credential import AppConfigurationCliCredential
180182
profile = Profile(cli_ctx=cmd.cli_ctx)
181183
cred, _, _ = profile.get_login_credentials()
184+
185+
current_cloud = get_active_cloud(cmd.cli_ctx)
186+
token_audience = None
187+
if hasattr(current_cloud.endpoints, "appconfig_auth_token_audience"):
188+
token_audience = current_cloud.endpoints.appconfig_auth_token_audience
189+
182190
try:
183-
azconfig_client = AzureAppConfigurationClient(credential=cred,
191+
azconfig_client = AzureAppConfigurationClient(credential=AppConfigurationCliCredential(cred._credential, token_audience), # pylint: disable=protected-access
184192
base_url=endpoint,
185193
user_agent=HttpHeaders.USER_AGENT)
186194
except (ValueError, TypeError) as ex:

0 commit comments

Comments
 (0)