Skip to content

Commit 30ef839

Browse files
committed
Merge branch 'dev' into wam
2 parents 6b9ef94 + 1b5d2d6 commit 30ef839

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

msal/application.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ def initiate_auth_code_flow(
676676
domain_hint=None, # type: Optional[str]
677677
claims_challenge=None,
678678
max_age=None,
679+
response_mode=None, # type: Optional[str]
679680
):
680681
"""Initiate an auth code flow.
681682
@@ -717,6 +718,20 @@ def initiate_auth_code_flow(
717718
718719
New in version 1.15.
719720
721+
:param str response_mode:
722+
OPTIONAL. Specifies the method with which response parameters should be returned.
723+
The default value is equivalent to ``query``, which is still secure enough in MSAL Python
724+
(because MSAL Python does not transfer tokens via query parameter in the first place).
725+
For even better security, we recommend using the value ``form_post``.
726+
In "form_post" mode, response parameters
727+
will be encoded as HTML form values that are transmitted via the HTTP POST method and
728+
encoded in the body using the application/x-www-form-urlencoded format.
729+
Valid values can be either "form_post" for HTTP POST to callback URI or
730+
"query" (the default) for HTTP GET with parameters encoded in query string.
731+
More information on possible values
732+
`here <https://openid.net/specs/oauth-v2-multiple-response-types-1_0.html#ResponseModes>`
733+
and `here <https://openid.net/specs/oauth-v2-form-post-response-mode-1_0.html#FormPostResponseMode>`
734+
720735
:return:
721736
The auth code flow. It is a dict in this form::
722737
@@ -747,6 +762,7 @@ def initiate_auth_code_flow(
747762
claims=_merge_claims_challenge_and_capabilities(
748763
self._client_capabilities, claims_challenge),
749764
max_age=max_age,
765+
response_mode=response_mode,
750766
)
751767
flow["claims_challenge"] = claims_challenge
752768
return flow

tests/msaltest.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,28 @@ def acquire_token_silent(app):
6363
))
6464

6565
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,
7779
)
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
7888

7989
def acquire_token_interactive(app):
8090
"""acquire_token_interactive() - User will be prompted if app opts to do select_account."""
@@ -119,14 +129,16 @@ def remove_account(app):
119129

120130
def exit(_):
121131
"""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))
123134
sys.exit()
124135

125136
def main():
126137
print("Welcome to the Msal Python Console Test App, committed at 2022-5-2\n")
127138
chosen_app = _select_options([
128139
{"client_id": "04b07795-8ddb-461a-bbee-02f9e1bf7b46", "name": "Azure CLI (Correctly configured for MSA-PT)"},
129140
{"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.)"},
130142
],
131143
option_renderer=lambda a: a["name"],
132144
header="Impersonate this app (or you can type in the client_id of your own app)",

0 commit comments

Comments
 (0)