Skip to content

Commit 9843d6f

Browse files
committed
Exposes the enable_msa_passthrough flag
1 parent 649d0e9 commit 9843d6f

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

msal/application.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,7 @@ def acquire_token_interactive(
15981598
extra_scopes_to_consent=None,
15991599
max_age=None,
16001600
window=None,
1601+
enable_msa_passthrough=None,
16011602
**kwargs):
16021603
"""Acquire token interactively i.e. via a local browser.
16031604
@@ -1660,6 +1661,13 @@ def acquire_token_interactive(
16601661
you are recommended to also provide its window handle,
16611662
so that the sign in UI window will properly pop up on top of your window.
16621663
1664+
:param boolean enable_msa_passthrough:
1665+
OPTIONAL. MSA-Passthrough is a legacy configuration,
1666+
needed by a small amount of Microsoft first-party apps,
1667+
which would login MSA accounts via ".../organizations" authority.
1668+
If you app belongs to this category, AND you are enabling broker,
1669+
you would want to enable this flag. Default value is equivalent to False.
1670+
16631671
:return:
16641672
- A dict containing no "error" key,
16651673
and typically contains an "access_token" key.
@@ -1686,14 +1694,21 @@ def acquire_token_interactive(
16861694
"no" if self.authority._validate_authority is False
16871695
or self.authority.is_adfs or self.authority._is_b2c
16881696
else None)
1689-
1697+
enable_msa_passthrough = self.client_id in [
1698+
# Experimental: Automatically enable MSA-PT mode for known MSA-PT apps
1699+
# More background of MSA-PT is available from this internal docs:
1700+
# https://microsoft.sharepoint.com/:w:/t/Identity-DevEx/EatIUauX3c9Ctw1l7AQ6iM8B5CeBZxc58eoQCE0IuZ0VFw?e=tgc3jP&CID=39c853be-76ea-79d7-ee73-f1b2706ede05
1701+
"04b07795-8ddb-461a-bbee-02f9e1bf7b46", # Azure CLI
1702+
"04f0c124-f2bc-4f59-8241-bf6df9866bbd", # Visual Studio
1703+
] if enable_msa_passthrough is None else enable_msa_passthrough
16901704
# Call _signin_silently() and/or _signin_interactively()
16911705
if prompt == "none" or (not prompt and not login_hint):
16921706
response = _signin_silently(
16931707
authority, self.client_id, scopes,
16941708
validateAuthority=validate_authority,
16951709
claims=claims,
16961710
max_age=max_age,
1711+
enable_msa_pt=enable_msa_passthrough,
16971712
**kwargs.get("data", {}))
16981713
import pymsalruntime
16991714
if prompt == "none" or response.get("_broker_status") not in (
@@ -1710,6 +1725,7 @@ def acquire_token_interactive(
17101725
claims=claims,
17111726
max_age=max_age,
17121727
window=window,
1728+
enable_msa_pt=enable_msa_passthrough,
17131729
**kwargs.get("data", {}))
17141730
return self._process_broker_response(response, scopes, kwargs.get("data", {}))
17151731

msal/broker.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,14 @@ def _get_new_correlation_id():
104104
return str(uuid.uuid4())
105105

106106

107-
def _enable_msa_pt_when_needed(params, client_id):
108-
if client_id in [ # Experimental: Automatically enable MSA-PT mode for known MSA-PT apps
109-
# More background of MSA-PT is available from this internal docs:
110-
# https://microsoft.sharepoint.com/:w:/t/Identity-DevEx/EatIUauX3c9Ctw1l7AQ6iM8B5CeBZxc58eoQCE0IuZ0VFw?e=tgc3jP&CID=39c853be-76ea-79d7-ee73-f1b2706ede05
111-
"04b07795-8ddb-461a-bbee-02f9e1bf7b46", # Azure CLI
112-
"04f0c124-f2bc-4f59-8241-bf6df9866bbd", # Visual Studio
113-
]:
114-
params.set_additional_parameter("msal_request_type", "consumer_passthrough") # PyMsalRuntime 0.8+
107+
def _enable_msa_pt(params):
108+
params.set_additional_parameter("msal_request_type", "consumer_passthrough") # PyMsalRuntime 0.8+
115109

116110

117-
def _signin_silently(authority, client_id, scopes, correlation_id=None, claims=None, **kwargs):
111+
def _signin_silently(
112+
authority, client_id, scopes, correlation_id=None, claims=None,
113+
enable_msa_pt=False,
114+
**kwargs):
118115
params = pymsalruntime.MSALRuntimeAuthParameters(client_id, authority)
119116
params.set_requested_scopes(scopes)
120117
if claims:
@@ -123,7 +120,8 @@ def _signin_silently(authority, client_id, scopes, correlation_id=None, claims=N
123120
for k, v in kwargs.items(): # This can be used to support domain_hint, max_age, etc.
124121
if v is not None:
125122
params.set_additional_parameter(k, str(v))
126-
_enable_msa_pt_when_needed(params, client_id)
123+
if enable_msa_pt:
124+
_enable_msa_pt(params)
127125
pymsalruntime.signin_silently(
128126
params,
129127
correlation_id or _get_new_correlation_id(),
@@ -139,6 +137,7 @@ def _signin_interactively(
139137
login_hint=None,
140138
claims=None,
141139
correlation_id=None,
140+
enable_msa_pt=False,
142141
**kwargs):
143142
params = pymsalruntime.MSALRuntimeAuthParameters(client_id, authority)
144143
params.set_requested_scopes(scopes)
@@ -156,7 +155,8 @@ def _signin_interactively(
156155
logger.warning("Using both select_account and login_hint is ambiguous. Ignoring login_hint.")
157156
else:
158157
logger.warning("prompt=%s is not supported by this module", prompt)
159-
_enable_msa_pt_when_needed(params, client_id)
158+
if enable_msa_pt:
159+
_enable_msa_pt(params)
160160
for k, v in kwargs.items(): # This can be used to support domain_hint, max_age, etc.
161161
if v is not None:
162162
params.set_additional_parameter(k, str(v))

0 commit comments

Comments
 (0)