@@ -63,18 +63,28 @@ def acquire_token_silent(app):
63
63
))
64
64
65
65
def _acquire_token_interactive (app , scopes , data = None ):
66
- return app .acquire_token_interactive (
67
- scopes ,
68
- prompt = _select_options ([
69
- {"value" : None , "description" : "Unspecified. Proceed silently with a default account (if any), fallback to prompt." },
70
- {"value" : "none" , "description" : "none. Proceed silently with a default account (if any), or error out." },
71
- {"value" : "select_account" , "description" : "select_account. Prompt with an account picker." },
72
- ],
73
- option_renderer = lambda o : o ["description" ],
74
- header = "Prompt behavior?" )["value" ],
75
- login_hint = _input ("login_hint (typically an email address, or leave it blank if you don't need one): " ) or None ,
76
- data = data or {},
66
+ prompt = _select_options ([
67
+ {"value" : None , "description" : "Unspecified. Proceed silently with a default account (if any), fallback to prompt." },
68
+ {"value" : "none" , "description" : "none. Proceed silently with a default account (if any), or error out." },
69
+ {"value" : "select_account" , "description" : "select_account. Prompt with an account picker." },
70
+ ],
71
+ option_renderer = lambda o : o ["description" ],
72
+ header = "Prompt behavior?" )["value" ]
73
+ raw_login_hint = _select_options (
74
+ # login_hint is unnecessary when prompt=select_account,
75
+ # but we still let tester input login_hint, just for testing purpose.
76
+ [None ] + [a ["username" ] for a in app .get_accounts ()],
77
+ header = "login_hint? (If you have multiple signed-in sessions in browser, and you specify a login_hint to match one of them, you will bypass the account picker.)" ,
78
+ accept_nonempty_string = True ,
77
79
)
80
+ login_hint = raw_login_hint ["username" ] if isinstance (raw_login_hint , dict ) else raw_login_hint
81
+ result = app .acquire_token_interactive (
82
+ scopes , prompt = prompt , login_hint = login_hint , data = data or {})
83
+ if login_hint and "id_token_claims" in result :
84
+ signed_in_user = result .get ("id_token_claims" , {}).get ("preferred_username" )
85
+ if signed_in_user != login_hint :
86
+ logging .warning ('Signed-in user "%s" does not match login_hint' , signed_in_user )
87
+ return result
78
88
79
89
def acquire_token_interactive (app ):
80
90
"""acquire_token_interactive() - User will be prompted if app opts to do select_account."""
@@ -119,14 +129,16 @@ def remove_account(app):
119
129
120
130
def exit (_ ):
121
131
"""Exit"""
122
- print ("Bye" )
132
+ bug_link = "https://github.com/AzureAD/microsoft-authentication-library-for-python/issues/new/choose"
133
+ print ("Bye. If you found a bug, please report it here: {}" .format (bug_link ))
123
134
sys .exit ()
124
135
125
136
def main ():
126
137
print ("Welcome to the Msal Python Console Test App, committed at 2022-5-2\n " )
127
138
chosen_app = _select_options ([
128
139
{"client_id" : "04b07795-8ddb-461a-bbee-02f9e1bf7b46" , "name" : "Azure CLI (Correctly configured for MSA-PT)" },
129
140
{"client_id" : "04f0c124-f2bc-4f59-8241-bf6df9866bbd" , "name" : "Visual Studio (Correctly configured for MSA-PT)" },
141
+ {"client_id" : "95de633a-083e-42f5-b444-a4295d8e9314" , "name" : "Whiteboard Services (Non MSA-PT app. Accepts AAD & MSA accounts.)" },
130
142
],
131
143
option_renderer = lambda a : a ["name" ],
132
144
header = "Impersonate this app (or you can type in the client_id of your own app)" ,
0 commit comments