Skip to content

Commit 6db1447

Browse files
committed
Bypass B2C
1 parent effe4aa commit 6db1447

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
@@ -470,9 +470,11 @@ def __init__(
470470
self.http_client, validate_authority=False)
471471
else:
472472
raise
473-
self._enable_broker = (
474-
isinstance(self, PublicClientApplication) # Exclude Confidential ROPC
475-
and sys.platform == "win32" and not self.authority.is_adfs)
473+
is_public_app = (isinstance(self, PublicClientApplication) or
474+
(isinstance(self, ClientApplication) and not self.client_credential))
475+
self._enable_broker = (is_public_app
476+
and sys.platform == "win32"
477+
and not self.authority.is_adfs and not self.authority._is_b2c)
476478

477479
self.token_cache = token_cache or TokenCache()
478480
self._region_configured = azure_region
@@ -1229,7 +1231,7 @@ def _acquire_token_silent_from_cache_and_possibly_refresh_it(
12291231
try:
12301232
from .wam import _acquire_token_silently
12311233
response = _acquire_token_silently(
1232-
"https://{}/{}".format(self.authority.instance, self.authority.tenant), # TODO: What about B2C & ADFS?
1234+
"https://{}/{}".format(self.authority.instance, self.authority.tenant),
12331235
self.client_id,
12341236
account["local_account_id"],
12351237
scopes,
@@ -1442,14 +1444,14 @@ def acquire_token_by_username_password(
14421444
try:
14431445
from .wam import _signin_silently, RedirectUriError
14441446
response = _signin_silently(
1445-
"https://{}/{}".format(self.authority.instance, self.authority.tenant), # TODO: What about B2C?
1447+
"https://{}/{}".format(self.authority.instance, self.authority.tenant),
14461448
self.client_id,
14471449
scopes, # Decorated scopes won't work due to offline_access
14481450
MSALRuntime_Username=username,
14491451
MSALRuntime_Password=password,
14501452
validateAuthority="no"
14511453
if self.authority._validate_authority is False
1452-
or self.authority.is_adfs
1454+
or self.authority.is_adfs or self.authority._is_b2c
14531455
else None,
14541456
claims=claims,
14551457
)
@@ -1629,12 +1631,12 @@ def acquire_token_interactive(
16291631
if "welcome_template" in kwargs:
16301632
logger.debug(kwargs["welcome_template"]) # Experimental
16311633
response = _signin_interactively(
1632-
"https://{}/{}".format(self.authority.instance, self.authority.tenant), # TODO: What about B2C?
1634+
"https://{}/{}".format(self.authority.instance, self.authority.tenant),
16331635
self.client_id,
16341636
scopes,
16351637
validateAuthority="no"
16361638
if self.authority._validate_authority is False
1637-
or self.authority.is_adfs
1639+
or self.authority.is_adfs or self.authority._is_b2c
16381640
else None,
16391641
login_hint=login_hint,
16401642
prompt=prompt,

msal/authority.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ def __init__(self, authority_url, http_client, validate_authority=True):
7272
authority_url = str(authority_url)
7373
authority, self.instance, tenant = canonicalize(authority_url)
7474
parts = authority.path.split('/')
75-
is_b2c = any(self.instance.endswith("." + d) for d in WELL_KNOWN_B2C_HOSTS) or (
75+
self._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_"))
7777
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
78+
if (tenant != "adfs" and (not self._is_b2c) and self._validate_authority
7979
and self.instance not in WELL_KNOWN_AUTHORITY_HOSTS):
8080
payload = instance_discovery(
8181
"https://{}{}/oauth2/v2.0/authorize".format(

tests/test_e2e.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -685,18 +685,9 @@ 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-
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)
688+
self._test_acquire_token_interactive(
689+
username_uri="https://msidlab.com/api/user?usertype=onprem&federationprovider=ADFSv2019",
690+
**config)
700691

701692
@unittest.skipUnless(
702693
os.getenv("LAB_OBO_CLIENT_SECRET"),

0 commit comments

Comments
 (0)