Skip to content

Commit 8b1bbcd

Browse files
committed
Support ADFS (pending PyMsalRuntime's ADFS support)
Experimental welcome_template support for testing Adjust test cases to expect PyMsalRuntime failure on ADFS
1 parent 457d2d1 commit 8b1bbcd

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

msal/application.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1593,10 +1593,16 @@ def acquire_token_interactive(
15931593
logger.warning(
15941594
"Ignoring parameter extra_scopes_to_consent, "
15951595
"which is not supported on current platform")
1596+
if "welcome_template" in kwargs:
1597+
logger.debug(kwargs["welcome_template"]) # Experimental
15961598
response = _signin_interactively(
1597-
"https://{}/{}".format(self.authority.instance, self.authority.tenant), # TODO: What about B2C & ADFS?
1599+
"https://{}/{}".format(self.authority.instance, self.authority.tenant), # TODO: What about B2C?
15981600
self.client_id,
15991601
scopes,
1602+
validateAuthority="no"
1603+
if self.authority._validate_authority is False
1604+
or self.authority.is_adfs
1605+
else None,
16001606
login_hint=login_hint,
16011607
prompt=prompt,
16021608
claims=claims,

msal/authority.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ def __init__(self, authority_url, http_client, validate_authority=True):
7474
parts = authority.path.split('/')
7575
is_b2c = any(self.instance.endswith("." + d) for d in WELL_KNOWN_B2C_HOSTS) or (
7676
len(parts) == 3 and parts[2].lower().startswith("b2c_"))
77-
if (tenant != "adfs" and (not is_b2c) and validate_authority
77+
self._validate_authority = True if validate_authority is None else bool(validate_authority)
78+
if (tenant != "adfs" and (not is_b2c) and self._validate_authority
7879
and self.instance not in WELL_KNOWN_AUTHORITY_HOSTS):
7980
payload = instance_discovery(
8081
"https://{}{}/oauth2/v2.0/authorize".format(

tests/test_e2e.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,18 @@ def test_adfs2019_onprem_acquire_token_interactive(self):
685685
config["authority"] = "https://fs.%s.com/adfs" % config["lab_name"]
686686
config["scope"] = self.adfs2019_scopes
687687
config["port"] = 8080
688-
self._test_acquire_token_interactive(
689-
username_uri="https://msidlab.com/api/user?usertype=onprem&federationprovider=ADFSv2019",
690-
**config)
688+
username_uri = "https://msidlab.com/api/user?usertype=onprem&federationprovider=ADFSv2019"
689+
try:
690+
import pymsalruntime
691+
logger.warning("Absorbing an AssertionError because PyMsalRuntime does not yet support onprem ADFS")
692+
with self.assertRaises(AssertionError): # Expecting a failure because
693+
# PyMsalRuntime does not yet support on-prem ADFS.
694+
# But if this expectation is not met,
695+
# it would mean the latest PyMsalRuntime supports onprem ADFS.
696+
# At that time we would revert this patch.
697+
self._test_acquire_token_interactive(username_uri=username_uri, **config)
698+
except ImportError: # Then use browser-based interactive flow, which will work
699+
self._test_acquire_token_interactive(username_uri=username_uri, **config)
691700

692701
@unittest.skipUnless(
693702
os.getenv("LAB_OBO_CLIENT_SECRET"),

0 commit comments

Comments
 (0)