Skip to content

Commit a457b72

Browse files
committed
Experimental: Auto detect MSA-Passthrough
1 parent 83bdffc commit a457b72

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

msal/broker.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ 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+
115+
116+
107117
def _signin_silently(authority, client_id, scopes, correlation_id=None, claims=None, **kwargs):
108118
params = pymsalruntime.MSALRuntimeAuthParameters(client_id, authority)
109119
params.set_requested_scopes(scopes)
@@ -113,6 +123,7 @@ def _signin_silently(authority, client_id, scopes, correlation_id=None, claims=N
113123
for k, v in kwargs.items(): # This can be used to support domain_hint, max_age, etc.
114124
if v is not None:
115125
params.set_additional_parameter(k, str(v))
126+
_enable_msa_pt_when_needed(params, client_id)
116127
pymsalruntime.signin_silently(
117128
params,
118129
correlation_id or _get_new_correlation_id(),
@@ -145,6 +156,7 @@ def _signin_interactively(
145156
logger.warning("Using both select_account and login_hint is ambiguous. Ignoring login_hint.")
146157
else:
147158
logger.warning("prompt=%s is not supported by this module", prompt)
159+
_enable_msa_pt_when_needed(params, client_id)
148160
for k, v in kwargs.items(): # This can be used to support domain_hint, max_age, etc.
149161
if v is not None:
150162
params.set_additional_parameter(k, str(v))

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
# The broker is defined as optional dependency,
9292
# so that downstream apps can opt in. The opt-in is needed, partially because
9393
# most existing MSAL Python apps do not have the redirect_uri needed by broker.
94-
"pymsalruntime>=0.7,<0.8;python_version>='3.6' and platform_system=='Windows'",
94+
"pymsalruntime>=0.8,<0.9;python_version>='3.6' and platform_system=='Windows'",
9595
],
9696
},
9797
)

0 commit comments

Comments
 (0)