File tree Expand file tree Collapse file tree 5 files changed +46
-4
lines changed
sdk/identity/azure-identity Expand file tree Collapse file tree 5 files changed +46
-4
lines changed Original file line number Diff line number Diff line change 11# Release History
22
3- ## 1.9.0 (Unreleased )
3+ ## 1.9.0 (2022-04-05 )
44
55### Features Added
66
7+ - Added PII logging if logging.DEBUG is enabled. ([ #23203 ] ( https://github.com/Azure/azure-sdk-for-python/issues/23203 ) )
8+
79### Breaking Changes
810
911- ` validate_authority ` support is not available in 1.9.0.
1012
1113### Bugs Fixed
1214
13- - Added check on ` content ` from msal response ([ #23483 ] ( https://github.com/Azure/azure-sdk-for-python/issues/23483 ) )
15+ - Added check on ` content ` from msal response. ([ #23483 ] ( https://github.com/Azure/azure-sdk-for-python/issues/23483 ) )
1416- Fixed the issue that async OBO credential does not refresh correctly. ([ #21981 ] ( https://github.com/Azure/azure-sdk-for-python/issues/21981 ) )
1517
1618### Other Changes
Original file line number Diff line number Diff line change 1212from .._internal import normalize_authority , validate_tenant_id
1313from .._internal .aad_client import AadClient
1414from .._internal .get_token_mixin import GetTokenMixin
15+ from .._internal .decorators import log_get_token
1516
1617if sys .platform .startswith ("win" ):
1718 from .._internal .win_vscode_adapter import get_refresh_token , get_user_settings
@@ -136,6 +137,7 @@ def close(self):
136137 """Close the credential's transport session."""
137138 self .__exit__ ()
138139
140+ @log_get_token ("VSCodeCredential" )
139141 def get_token (self , * scopes , ** kwargs ):
140142 # type: (*str, **Any) -> AccessToken
141143 """Request an access token for `scopes` as the user currently signed in to Visual Studio Code.
Original file line number Diff line number Diff line change 44# ------------------------------------
55import functools
66import logging
7+ import json
8+ import base64
79
810from six import raise_from
911from azure .core .exceptions import ClientAuthenticationError
@@ -31,8 +33,24 @@ def wrapper(*args, **kwargs):
3133 _LOGGER .log (
3234 logging .DEBUG if within_credential_chain .get () else logging .INFO , "%s succeeded" , qualified_name
3335 )
36+ if _LOGGER .isEnabledFor (logging .DEBUG ):
37+ try :
38+ base64_meta_data = token .token .split ("." )[1 ].encode ("utf-8" ) + b'=='
39+ json_bytes = base64 .decodebytes (base64_meta_data )
40+ json_string = json_bytes .decode ('utf-8' )
41+ json_dict = json .loads (json_string )
42+ upn = json_dict .get ('upn' , 'unavailableUpn' )
43+ log_string = '[Authenticated account] Client ID: {}. Tenant ID: {}. User Principal Name: {}. ' \
44+ 'Object ID (user): {}' .format (json_dict ['appid' ],
45+ json_dict ['tid' ],
46+ upn ,
47+ json_dict ['oid' ]
48+ )
49+ _LOGGER .debug (log_string )
50+ except Exception : # pylint: disable=broad-except
51+ _LOGGER .debug ("Fail to log the account information" )
3452 return token
35- except Exception as ex :
53+ except Exception as ex : # pylint: disable=broad-except
3654 _LOGGER .log (
3755 logging .DEBUG if within_credential_chain .get () else logging .WARNING ,
3856 "%s failed: %s" ,
Original file line number Diff line number Diff line change 88from .._internal import AsyncContextManager
99from .._internal .aad_client import AadClient
1010from .._internal .get_token_mixin import GetTokenMixin
11+ from .._internal .decorators import log_get_token_async
1112from ..._credentials .vscode import _VSCodeCredentialBase
1213
1314if TYPE_CHECKING :
@@ -39,6 +40,7 @@ async def close(self) -> None:
3940 if self ._client :
4041 await self ._client .__aexit__ ()
4142
43+ @log_get_token_async
4244 async def get_token (self , * scopes : str , ** kwargs : "Any" ) -> "AccessToken" :
4345 """Request an access token for `scopes` as the user currently signed in to Visual Studio Code.
4446
Original file line number Diff line number Diff line change 44# ------------------------------------
55import functools
66import logging
7+ import json
8+ import base64
79
810from azure .core .exceptions import ClientAuthenticationError
911
@@ -20,8 +22,24 @@ async def wrapper(*args, **kwargs):
2022 _LOGGER .log (
2123 logging .DEBUG if within_credential_chain .get () else logging .INFO , "%s succeeded" , fn .__qualname__
2224 )
25+ if _LOGGER .isEnabledFor (logging .DEBUG ):
26+ try :
27+ base64_meta_data = token .token .split ("." )[1 ].encode ("utf-8" ) + b'=='
28+ json_bytes = base64 .decodebytes (base64_meta_data )
29+ json_string = json_bytes .decode ('utf-8' )
30+ json_dict = json .loads (json_string )
31+ upn = json_dict .get ('upn' , 'unavailableUpn' )
32+ log_string = '[Authenticated account] Client ID: {}. Tenant ID: {}. User Principal Name: {}. ' \
33+ 'Object ID (user): {}' .format (json_dict ['appid' ],
34+ json_dict ['tid' ],
35+ upn ,
36+ json_dict ['oid' ]
37+ )
38+ _LOGGER .debug (log_string )
39+ except Exception : # pylint: disable=broad-except
40+ _LOGGER .debug ("Fail to log the account information" )
2341 return token
24- except Exception as ex :
42+ except Exception as ex : # pylint: disable=broad-except
2543 _LOGGER .log (
2644 logging .DEBUG if within_credential_chain .get () else logging .WARNING ,
2745 "%s failed: %s" ,
You can’t perform that action at this time.
0 commit comments