Skip to content

Commit 0183369

Browse files
committed
Bypass B2C
1 parent 0c0190f commit 0183369

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

msal/application.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,11 @@ def __init__(
466466
self.http_client, validate_authority=False)
467467
else:
468468
raise
469-
self._enable_broker = (
470-
isinstance(self, PublicClientApplication) # Exclude Confidential ROPC
471-
and sys.platform == "win32" and not self.authority.is_adfs)
469+
is_public_app = (isinstance(self, PublicClientApplication) or
470+
(isinstance(self, ClientApplication) and not self.client_credential))
471+
self._enable_broker = (is_public_app
472+
and sys.platform == "win32"
473+
and not self.authority.is_adfs and not self.authority._is_b2c)
472474

473475
self.token_cache = token_cache or TokenCache()
474476
self._region_configured = azure_region
@@ -1225,7 +1227,7 @@ def _acquire_token_silent_from_cache_and_possibly_refresh_it(
12251227
try:
12261228
from .wam import _acquire_token_silently
12271229
response = _acquire_token_silently(
1228-
"https://{}/{}".format(self.authority.instance, self.authority.tenant), # TODO: What about B2C & ADFS?
1230+
"https://{}/{}".format(self.authority.instance, self.authority.tenant),
12291231
self.client_id,
12301232
account["local_account_id"],
12311233
scopes,
@@ -1438,14 +1440,14 @@ def acquire_token_by_username_password(
14381440
try:
14391441
from .wam import _signin_silently, RedirectUriError
14401442
response = _signin_silently(
1441-
"https://{}/{}".format(self.authority.instance, self.authority.tenant), # TODO: What about B2C?
1443+
"https://{}/{}".format(self.authority.instance, self.authority.tenant),
14421444
self.client_id,
14431445
scopes, # Decorated scopes won't work due to offline_access
14441446
MSALRuntime_Username=username,
14451447
MSALRuntime_Password=password,
14461448
validateAuthority="no"
14471449
if self.authority._validate_authority is False
1448-
or self.authority.is_adfs
1450+
or self.authority.is_adfs or self.authority._is_b2c
14491451
else None,
14501452
claims=claims,
14511453
)
@@ -1625,12 +1627,12 @@ def acquire_token_interactive(
16251627
if "welcome_template" in kwargs:
16261628
logger.debug(kwargs["welcome_template"]) # Experimental
16271629
response = _signin_interactively(
1628-
"https://{}/{}".format(self.authority.instance, self.authority.tenant), # TODO: What about B2C?
1630+
"https://{}/{}".format(self.authority.instance, self.authority.tenant),
16291631
self.client_id,
16301632
scopes,
16311633
validateAuthority="no"
16321634
if self.authority._validate_authority is False
1633-
or self.authority.is_adfs
1635+
or self.authority.is_adfs or self.authority._is_b2c
16341636
else None,
16351637
login_hint=login_hint,
16361638
prompt=prompt,

msal/authority.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ def __init__(self, authority_url, http_client, validate_authority=True):
7777
authority_url = str(authority_url)
7878
authority, self.instance, tenant = canonicalize(authority_url)
7979
parts = authority.path.split('/')
80-
is_b2c = any(self.instance.endswith("." + d) for d in WELL_KNOWN_B2C_HOSTS) or (
80+
self._is_b2c = any(self.instance.endswith("." + d) for d in WELL_KNOWN_B2C_HOSTS) or (
8181
len(parts) == 3 and parts[2].lower().startswith("b2c_"))
8282
self._validate_authority = True if validate_authority is None else bool(validate_authority)
83-
if (tenant != "adfs" and (not is_b2c) and self._validate_authority
83+
if (tenant != "adfs" and (not self._is_b2c) and self._validate_authority
8484
and self.instance not in WELL_KNOWN_AUTHORITY_HOSTS):
8585
payload = instance_discovery(
8686
"https://{}{}/oauth2/v2.0/authorize".format(

tests/test_e2e.py

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

699690
@unittest.skipUnless(
700691
os.getenv("LAB_OBO_CLIENT_SECRET"),

0 commit comments

Comments
 (0)