Skip to content

Commit ca3cd48

Browse files
corykingpvaneck
andauthored
FIx key error in identity logging (Azure#37986)
The "appid" key is not always in json_dict. If you enable logging, things blow up because "appid" isn't always there. Signed-off-by: Paul Van Eck <[email protected]> Co-authored-by: Paul Van Eck <[email protected]>
1 parent e30c640 commit ca3cd48

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

sdk/identity/azure-identity/azure/identity/_internal/decorators.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ def wrapper(*args, **kwargs):
3131
json_string = json_bytes.decode("utf-8")
3232
json_dict = json.loads(json_string)
3333
upn = json_dict.get("upn", "unavailableUpn")
34+
appid = json_dict.get("appid", "<unavailable>")
35+
tid = json_dict.get("tid", "<unavailable>")
36+
oid = json_dict.get("oid", "<unavailable>")
3437
log_string = (
35-
"[Authenticated account] Client ID: {}. Tenant ID: {}. User Principal Name: {}. "
36-
"Object ID (user): {}".format(json_dict["appid"], json_dict["tid"], upn, json_dict["oid"])
38+
f"[Authenticated account] Client ID: {appid}. "
39+
f"Tenant ID: {tid}. User Principal Name: {upn}. Object ID (user): {oid}"
3740
)
3841
_LOGGER.debug(log_string)
3942
except Exception as ex: # pylint: disable=broad-except

sdk/identity/azure-identity/azure/identity/aio/_internal/decorators.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ async def wrapper(*args, **kwargs):
3030
json_string = json_bytes.decode("utf-8")
3131
json_dict = json.loads(json_string)
3232
upn = json_dict.get("upn", "unavailableUpn")
33+
appid = json_dict.get("appid", "<unavailable>")
34+
tid = json_dict.get("tid", "<unavailable>")
35+
oid = json_dict.get("oid", "<unavailable>")
3336
log_string = (
34-
"[Authenticated account] Client ID: {}. Tenant ID: {}. User Principal Name: {}. "
35-
"Object ID (user): {}".format(json_dict["appid"], json_dict["tid"], upn, json_dict["oid"])
37+
f"[Authenticated account] Client ID: {appid}. "
38+
f"Tenant ID: {tid}. User Principal Name: {upn}. Object ID (user): {oid}"
3639
)
3740
_LOGGER.debug(log_string)
3841
except Exception as ex: # pylint: disable=broad-except

0 commit comments

Comments
 (0)