Skip to content

Commit a558775

Browse files
authored
Merge pull request #247 from AzureAD/cache-tokens-by-specified-environment
Cache tokens by specified environment, not by OIDC Discovery
2 parents 6362806 + 361f90c commit a558775

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

msal/application.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ def _build_client(self, client_credential, authority):
274274
default_body=default_body,
275275
client_assertion=client_assertion,
276276
client_assertion_type=client_assertion_type,
277-
on_obtaining_tokens=self.token_cache.add,
277+
on_obtaining_tokens=lambda event: self.token_cache.add(dict(
278+
event, environment=authority.instance)),
278279
on_removing_rt=self.token_cache.remove_rt,
279280
on_updating_rt=self.token_cache.update_rt)
280281

msal/token_cache.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ def __add(self, event, now=None):
126126
environment = realm = None
127127
if "token_endpoint" in event:
128128
_, environment, realm = canonicalize(event["token_endpoint"])
129+
if "environment" in event: # Always available unless in legacy test cases
130+
environment = event["environment"] # Set by application.py
129131
response = event.get("response", {})
130132
data = event.get("data", {})
131133
access_token = response.get("access_token")

0 commit comments

Comments
 (0)