1212"""
1313import base64 , getpass , json , logging , sys , msal
1414
15+ # This tester can test scenarios of these apps
1516_AZURE_CLI = "04b07795-8ddb-461a-bbee-02f9e1bf7b46"
1617_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+ }
1735
1836def print_json (blob ):
1937 print (json .dumps (blob , indent = 2 , sort_keys = True ))
@@ -82,6 +100,13 @@ def _acquire_token_silent(app):
82100 force_refresh = _input_boolean ("Bypass MSAL Python's token cache?" ),
83101 ))
84102
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+
85110def _acquire_token_interactive (app , scopes = None , data = None ):
86111 """acquire_token_interactive() - User will be prompted if app opts to do select_account."""
87112 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):
108133 _AZURE_CLI , _VISUAL_STUDIO ,
109134 ], # Here this test app mimics the setting for some known MSA-PT apps
110135 prompt = prompt , login_hint = login_hint , data = data or {},
136+ path = _get_redirect_uri_path (app ),
111137 )
112138 if login_hint and "id_token_claims" in result :
113139 signed_in_user = result .get ("id_token_claims" , {}).get ("preferred_username" )
@@ -181,11 +207,8 @@ def _exit(app):
181207
182208def _main ():
183209 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 ()),
189212 option_renderer = lambda a : a ["name" ],
190213 header = "Impersonate this app (or you can type in the client_id of your own app)" ,
191214 accept_nonempty_string = True )
0 commit comments