Skip to content

Commit a04a010

Browse files
committed
Add constants
1 parent 3d6c838 commit a04a010

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/azure-cli-core/azure/cli/core/_profile.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,10 @@ def login_with_managed_identity_azure_arc(self, identity_id=None, allow_no_subsc
314314
import jwt
315315
identity_type = MsiAccountTypes.system_assigned
316316
from .auth.msal_credentials import ManagedIdentityCredential
317+
from .auth.constants import ACCESS_TOKEN
317318

318319
cred = ManagedIdentityCredential()
319-
token = cred.acquire_token(self._arm_scope)["access_token"]
320+
token = cred.acquire_token(self._arm_scope)[ACCESS_TOKEN]
320321
logger.info('Managed identity: token was retrieved. Now trying to initialize local accounts...')
321322
decode = jwt.decode(token, algorithms=['RS256'], options={"verify_signature": False})
322323
tenant = decode['tid']
@@ -340,9 +341,10 @@ def login_with_managed_identity_azure_arc(self, identity_id=None, allow_no_subsc
340341
def login_in_cloud_shell(self):
341342
import jwt
342343
from .auth.msal_credentials import CloudShellCredential
344+
from .auth.constants import ACCESS_TOKEN
343345

344346
cred = CloudShellCredential()
345-
token = cred.acquire_token(self._arm_scope)["access_token"]
347+
token = cred.acquire_token(self._arm_scope)[ACCESS_TOKEN]
346348
logger.info('Cloud Shell token was retrieved. Now trying to initialize local accounts...')
347349
decode = jwt.decode(token, algorithms=['RS256'], options={"verify_signature": False})
348350
tenant = decode['tid']

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
# --------------------------------------------------------------------------------------------
55

66
AZURE_CLI_CLIENT_ID = '04b07795-8ddb-461a-bbee-02f9e1bf7b46'
7+
8+
ACCESS_TOKEN = 'access_token'
9+
EXPIRES_IN = "expires_in"

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ def build_sdk_access_token(token_entry):
150150
# Importing azure.core.credentials.AccessToken is expensive.
151151
# This can slow down commands that doesn't need azure.core, like `az account get-access-token`.
152152
# So We define our own AccessToken.
153-
return AccessToken(token_entry["access_token"], _now_timestamp() + token_entry["expires_in"])
153+
from .constants import ACCESS_TOKEN, EXPIRES_IN
154+
return AccessToken(token_entry[ACCESS_TOKEN], _now_timestamp() + token_entry[EXPIRES_IN])
154155

155156

156157
def decode_access_token(access_token):

0 commit comments

Comments
 (0)