Skip to content

Commit 14965f7

Browse files
committed
Fine tune msaltest.py with prompt options
1 parent 0a62ead commit 14965f7

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

tests/msaltest.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _input_scopes():
3737
"User.Read",
3838
"User.ReadBasic.All",
3939
],
40-
header="Select a scope (multiple scopes can only be input by manually typing them):",
40+
header="Select a scope (multiple scopes can only be input by manually typing them, delimited by space):",
4141
accept_nonempty_string=True,
4242
).split()
4343

@@ -62,13 +62,23 @@ def acquire_token_silent(app):
6262
force_refresh=_input_boolean("Bypass MSAL Python's token cache?"),
6363
))
6464

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 {},
77+
)
78+
6579
def acquire_token_interactive(app):
6680
"""acquire_token_interactive() - User will be prompted if app opts to do select_account."""
67-
pprint.pprint(app.acquire_token_interactive(
68-
_input_scopes(),
69-
prompt="select_account" if _input_boolean("Select Account?") else None,
70-
login_hint=_input("login_hint: ") or None,
71-
))
81+
pprint.pprint(_acquire_token_interactive(app, _input_scopes()))
7282

7383
def acquire_token_by_username_password(app):
7484
"""acquire_token_by_username_password() - See constraints here: https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-authentication-flows#constraints-for-ropc"""
@@ -95,12 +105,7 @@ def acquire_ssh_cert_silently(app):
95105

96106
def acquire_ssh_cert_interactive(app):
97107
"""Acquire an SSH Cert interactively - This typically only works with Azure CLI"""
98-
result = app.acquire_token_interactive(
99-
SSH_CERT_SCOPE,
100-
prompt="select_account" if _input_boolean("Select Account?") else None,
101-
login_hint=_input("login_hint: ") or None,
102-
data=SSH_CERT_DATA,
103-
)
108+
result = _acquire_token_interactive(app, SSH_CERT_SCOPE, data=SSH_CERT_DATA)
104109
pprint.pprint(result)
105110
if result.get("token_type") != "ssh-cert":
106111
logging.error("Unable to acquire an ssh-cert")
@@ -118,9 +123,9 @@ def exit(_):
118123
sys.exit()
119124

120125
def main():
121-
print("Welcome to the Msal Python Console Test App")
126+
print("Welcome to the Msal Python Console Test App, committed at 2022-5-2\n")
122127
chosen_app = _select_options([
123-
{"client_id": "04b07795-8ddb-461a-bbee-02f9e1bf7b46", "name": "Azure CLI"},
128+
{"client_id": "04b07795-8ddb-461a-bbee-02f9e1bf7b46", "name": "Azure CLI (Correctly configured for MSA-PT)"},
124129
{"client_id": "04f0c124-f2bc-4f59-8241-bf6df9866bbd", "name": "Visual Studio (Correctly configured for MSA-PT)"},
125130
],
126131
option_renderer=lambda a: a["name"],
@@ -134,7 +139,10 @@ def main():
134139
"https://login.microsoftonline.com/microsoft.onmicrosoft.com",
135140
"https://login.microsoftonline.com/msidlab4.onmicrosoft.com",
136141
"https://login.microsoftonline.com/consumers",
137-
], header="Input authority", accept_nonempty_string=True),
142+
],
143+
header="Input authority (Note that MSA-PT apps would NOT use the /common authority)",
144+
accept_nonempty_string=True,
145+
),
138146
)
139147
if _input_boolean("Enable MSAL Python's DEBUG log?"):
140148
logging.basicConfig(level=logging.DEBUG)

0 commit comments

Comments
 (0)