12
12
"""
13
13
import base64 , getpass , json , logging , sys , msal
14
14
15
+ # This tester can test scenarios of these apps
15
16
_AZURE_CLI = "04b07795-8ddb-461a-bbee-02f9e1bf7b46"
16
17
_VISUAL_STUDIO = "04f0c124-f2bc-4f59-8241-bf6df9866bbd"
18
+ _WHITE_BOARD = "95de633a-083e-42f5-b444-a4295d8e9314"
19
+ _KNOWN_APPS = {
20
+ _AZURE_CLI : {
21
+ "client_id" : _AZURE_CLI ,
22
+ "name" : "Azure CLI (Correctly configured for MSA-PT)" ,
23
+ "path_in_redirect_uri" : None ,
24
+ },
25
+ _VISUAL_STUDIO : {
26
+ "client_id" : _VISUAL_STUDIO ,
27
+ "name" : "Visual Studio (Correctly configured for MSA-PT)" ,
28
+ "path_in_redirect_uri" : None ,
29
+ },
30
+ _WHITE_BOARD : {
31
+ "client_id" : _WHITE_BOARD ,
32
+ "name" : "Whiteboard Services (Non MSA-PT app. Accepts AAD & MSA accounts.)" ,
33
+ },
34
+ }
17
35
18
36
def print_json (blob ):
19
37
print (json .dumps (blob , indent = 2 , sort_keys = True ))
@@ -82,6 +100,13 @@ def _acquire_token_silent(app):
82
100
force_refresh = _input_boolean ("Bypass MSAL Python's token cache?" ),
83
101
))
84
102
103
+ def _get_redirect_uri_path (app ):
104
+ if app ._enable_broker :
105
+ return None
106
+ if "path_in_redirect_uri" in _KNOWN_APPS .get (app .client_id , {}):
107
+ return _KNOWN_APPS [app .client_id ]["path_in_redirect_uri" ]
108
+ return input ("What is the path in this app's redirect_uri?" )
109
+
85
110
def _acquire_token_interactive (app , scopes = None , data = None ):
86
111
"""acquire_token_interactive() - User will be prompted if app opts to do select_account."""
87
112
scopes = scopes or _input_scopes () # Let user input scope param before less important prompt and login_hint
@@ -108,6 +133,7 @@ def _acquire_token_interactive(app, scopes=None, data=None):
108
133
_AZURE_CLI , _VISUAL_STUDIO ,
109
134
], # Here this test app mimics the setting for some known MSA-PT apps
110
135
prompt = prompt , login_hint = login_hint , data = data or {},
136
+ path = _get_redirect_uri_path (app ),
111
137
)
112
138
if login_hint and "id_token_claims" in result :
113
139
signed_in_user = result .get ("id_token_claims" , {}).get ("preferred_username" )
@@ -181,11 +207,8 @@ def _exit(app):
181
207
182
208
def _main ():
183
209
print ("Welcome to the Msal Python {} Tester (Experimental)\n " .format (msal .__version__ ))
184
- chosen_app = _select_options ([
185
- {"client_id" : _AZURE_CLI , "name" : "Azure CLI (Correctly configured for MSA-PT)" },
186
- {"client_id" : _VISUAL_STUDIO , "name" : "Visual Studio (Correctly configured for MSA-PT)" },
187
- {"client_id" : "95de633a-083e-42f5-b444-a4295d8e9314" , "name" : "Whiteboard Services (Non MSA-PT app. Accepts AAD & MSA accounts.)" },
188
- ],
210
+ chosen_app = _select_options (
211
+ list (_KNOWN_APPS .values ()),
189
212
option_renderer = lambda a : a ["name" ],
190
213
header = "Impersonate this app (or you can type in the client_id of your own app)" ,
191
214
accept_nonempty_string = True )
0 commit comments