Skip to content

Commit f285074

Browse files
authored
Merge pull request #237 from AzureAD/release-1.4.3
MSAL Python 1.4.3
2 parents 4e2ed20 + ece3918 commit f285074

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

msal/application.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
# The __init__.py will import this. Not the other way around.
24-
__version__ = "1.4.2"
24+
__version__ = "1.4.3"
2525

2626
logger = logging.getLogger(__name__)
2727

@@ -554,7 +554,9 @@ def acquire_token_silent_with_error(
554554
for alias in self._get_authority_aliases(self.authority.instance):
555555
if not self.token_cache.find(
556556
self.token_cache.CredentialType.REFRESH_TOKEN,
557-
target=scopes,
557+
# target=scopes, # MUST NOT filter by scopes, because:
558+
# 1. AAD RTs are scope-independent;
559+
# 2. therefore target is optional per schema;
558560
query={"environment": alias}):
559561
# Skip heavy weight logic when RT for this alias doesn't exist
560562
continue

tests/test_application.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,21 +240,30 @@ def setUp(self):
240240
uid=uid, utid=utid,
241241
access_token=self.access_token, refresh_token="some refresh token"),
242242
}) # The add(...) helper populates correct home_account_id for future searching
243-
244-
def test_get_accounts(self):
245-
app = ClientApplication(
243+
self.app = ClientApplication(
246244
self.client_id,
247245
authority=self.authority_url_in_app, token_cache=self.cache)
248-
accounts = app.get_accounts()
246+
247+
def test_get_accounts_should_find_accounts_under_different_alias(self):
248+
accounts = self.app.get_accounts()
249249
self.assertNotEqual([], accounts)
250250
self.assertEqual(self.environment_in_cache, accounts[0].get("environment"),
251251
"We should be able to find an account under an authority alias")
252252

253-
def test_acquire_token_silent(self):
254-
app = ClientApplication(
255-
self.client_id,
256-
authority=self.authority_url_in_app, token_cache=self.cache)
257-
at = app.acquire_token_silent(self.scopes, self.account)
258-
self.assertNotEqual(None, at)
259-
self.assertEqual(self.access_token, at.get('access_token'))
253+
def test_acquire_token_silent_should_find_at_under_different_alias(self):
254+
result = self.app.acquire_token_silent(self.scopes, self.account)
255+
self.assertNotEqual(None, result)
256+
self.assertEqual(self.access_token, result.get('access_token'))
257+
258+
def test_acquire_token_silent_should_find_rt_under_different_alias(self):
259+
self.cache._cache["AccessToken"] = {} # A hacky way to clear ATs
260+
class ExpectedBehavior(Exception):
261+
pass
262+
def helper(scopes, account, authority, *args, **kwargs):
263+
if authority.instance == self.environment_in_cache:
264+
raise ExpectedBehavior("RT of different alias being attempted")
265+
self.app._acquire_token_silent_from_cache_and_possibly_refresh_it = helper
266+
267+
with self.assertRaises(ExpectedBehavior):
268+
self.app.acquire_token_silent(["different scope"], self.account)
260269

0 commit comments

Comments
 (0)