Skip to content

Commit 361f90c

Browse files
committed
Cache tokens by specified environment, not by OIDC Discovery
1 parent f1243f2 commit 361f90c

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
@@ -246,7 +246,8 @@ def _build_client(self, client_credential, authority):
246246
default_body=default_body,
247247
client_assertion=client_assertion,
248248
client_assertion_type=client_assertion_type,
249-
on_obtaining_tokens=self.token_cache.add,
249+
on_obtaining_tokens=lambda event: self.token_cache.add(dict(
250+
event, environment=authority.instance)),
250251
on_removing_rt=self.token_cache.remove_rt,
251252
on_updating_rt=self.token_cache.update_rt)
252253

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)