1- import getpass , logging , pprint , sys , msal
1+ import getpass , json , logging , sys , msal
22
33
44AZURE_CLI = "04b07795-8ddb-461a-bbee-02f9e1bf7b46"
55VISUAL_STUDIO = "04f0c124-f2bc-4f59-8241-bf6df9866bbd"
66
7+ def print_json (blob ):
8+ print (json .dumps (blob , indent = 2 ))
9+
710def _input_boolean (message ):
811 return input (
912 "{} (N/n/F/f or empty means False, otherwise it is True): " .format (message )
@@ -62,7 +65,7 @@ def acquire_token_silent(app):
6265 """acquire_token_silent() - with an account already signed into MSAL Python."""
6366 account = _select_account (app )
6467 if account :
65- pprint . pprint (app .acquire_token_silent (
68+ print_json (app .acquire_token_silent (
6669 _input_scopes (),
6770 account = account ,
6871 force_refresh = _input_boolean ("Bypass MSAL Python's token cache?" ),
@@ -99,11 +102,11 @@ def _acquire_token_interactive(app, scopes, data=None):
99102
100103def acquire_token_interactive (app ):
101104 """acquire_token_interactive() - User will be prompted if app opts to do select_account."""
102- pprint . pprint (_acquire_token_interactive (app , _input_scopes ()))
105+ print_json (_acquire_token_interactive (app , _input_scopes ()))
103106
104107def acquire_token_by_username_password (app ):
105108 """acquire_token_by_username_password() - See constraints here: https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-authentication-flows#constraints-for-ropc"""
106- pprint . pprint (app .acquire_token_by_username_password (
109+ print_json (app .acquire_token_by_username_password (
107110 _input ("username: " ), getpass .getpass ("password: " ), scopes = _input_scopes ()))
108111
109112_JWK1 = """{"kty":"RSA", "n":"2tNr73xwcj6lH7bqRZrFzgSLj7OeLfbn8216uOMDHuaZ6TEUBDN8Uz0ve8jAlKsP9CQFCSVoSNovdE-fs7c15MxEGHjDcNKLWonznximj8pDGZQjVdfK-7mG6P6z-lgVcLuYu5JcWU_PeEqIKg5llOaz-qeQ4LEDS4T1D2qWRGpAra4rJX1-kmrWmX_XIamq30C9EIO0gGuT4rc2hJBWQ-4-FnE1NXmy125wfT3NdotAJGq5lMIfhjfglDbJCwhc8Oe17ORjO3FsB5CLuBRpYmP7Nzn66lRY3Fe11Xz8AEBl3anKFSJcTvlMnFtu3EpD-eiaHfTgRBU7CztGQqVbiQ", "e":"AQAB"}"""
@@ -120,14 +123,14 @@ def acquire_ssh_cert_silently(app):
120123 data = SSH_CERT_DATA ,
121124 force_refresh = _input_boolean ("Bypass MSAL Python's token cache?" ),
122125 )
123- pprint . pprint (result )
126+ print_json (result )
124127 if result and result .get ("token_type" ) != "ssh-cert" :
125128 logging .error ("Unable to acquire an ssh-cert." )
126129
127130def acquire_ssh_cert_interactive (app ):
128131 """Acquire an SSH Cert interactively - This typically only works with Azure CLI"""
129132 result = _acquire_token_interactive (app , SSH_CERT_SCOPE , data = SSH_CERT_DATA )
130- pprint . pprint (result )
133+ print_json (result )
131134 if result .get ("token_type" ) != "ssh-cert" :
132135 logging .error ("Unable to acquire an ssh-cert" )
133136
@@ -149,7 +152,7 @@ def exit(app):
149152 sys .exit ()
150153
151154def main ():
152- print ("Welcome to the Msal Python Console Test App, committed at 2022-5-2 \n " )
155+ print ("Welcome to the Msal Python {} Tester \n " . format ( msal . __version__ ) )
153156 chosen_app = _select_options ([
154157 {"client_id" : AZURE_CLI , "name" : "Azure CLI (Correctly configured for MSA-PT)" },
155158 {"client_id" : VISUAL_STUDIO , "name" : "Visual Studio (Correctly configured for MSA-PT)" },
0 commit comments