1
- import getpass , logging , pprint , sys , msal
1
+ import getpass , json , logging , sys , msal
2
2
3
3
4
4
AZURE_CLI = "04b07795-8ddb-461a-bbee-02f9e1bf7b46"
5
5
VISUAL_STUDIO = "04f0c124-f2bc-4f59-8241-bf6df9866bbd"
6
6
7
+ def print_json (blob ):
8
+ print (json .dumps (blob , indent = 2 ))
9
+
7
10
def _input_boolean (message ):
8
11
return input (
9
12
"{} (N/n/F/f or empty means False, otherwise it is True): " .format (message )
@@ -62,7 +65,7 @@ def acquire_token_silent(app):
62
65
"""acquire_token_silent() - with an account already signed into MSAL Python."""
63
66
account = _select_account (app )
64
67
if account :
65
- pprint . pprint (app .acquire_token_silent (
68
+ print_json (app .acquire_token_silent (
66
69
_input_scopes (),
67
70
account = account ,
68
71
force_refresh = _input_boolean ("Bypass MSAL Python's token cache?" ),
@@ -99,11 +102,11 @@ def _acquire_token_interactive(app, scopes, data=None):
99
102
100
103
def acquire_token_interactive (app ):
101
104
"""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 ()))
103
106
104
107
def acquire_token_by_username_password (app ):
105
108
"""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 (
107
110
_input ("username: " ), getpass .getpass ("password: " ), scopes = _input_scopes ()))
108
111
109
112
_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):
120
123
data = SSH_CERT_DATA ,
121
124
force_refresh = _input_boolean ("Bypass MSAL Python's token cache?" ),
122
125
)
123
- pprint . pprint (result )
126
+ print_json (result )
124
127
if result and result .get ("token_type" ) != "ssh-cert" :
125
128
logging .error ("Unable to acquire an ssh-cert." )
126
129
127
130
def acquire_ssh_cert_interactive (app ):
128
131
"""Acquire an SSH Cert interactively - This typically only works with Azure CLI"""
129
132
result = _acquire_token_interactive (app , SSH_CERT_SCOPE , data = SSH_CERT_DATA )
130
- pprint . pprint (result )
133
+ print_json (result )
131
134
if result .get ("token_type" ) != "ssh-cert" :
132
135
logging .error ("Unable to acquire an ssh-cert" )
133
136
@@ -149,7 +152,7 @@ def exit(app):
149
152
sys .exit ()
150
153
151
154
def 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__ ) )
153
156
chosen_app = _select_options ([
154
157
{"client_id" : AZURE_CLI , "name" : "Azure CLI (Correctly configured for MSA-PT)" },
155
158
{"client_id" : VISUAL_STUDIO , "name" : "Visual Studio (Correctly configured for MSA-PT)" },
0 commit comments