Skip to content

Commit f5d30d0

Browse files
committed
Cache will record AppMetadata from now on
1 parent 3419f87 commit f5d30d0

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

msal/token_cache.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class CredentialType:
3030
REFRESH_TOKEN = "RefreshToken"
3131
ACCOUNT = "Account" # Not exactly a credential type, but we put it here
3232
ID_TOKEN = "IdToken"
33+
APP_METADATA = "AppMetadata"
3334

3435
class AuthorityType:
3536
ADFS = "ADFS"
@@ -162,6 +163,17 @@ def add(self, event, now=None):
162163
rt["family_id"] = response["foci"]
163164
self._cache.setdefault(self.CredentialType.REFRESH_TOKEN, {})[key] = rt
164165

166+
key = self._build_appmetadata_key(environment, event.get("client_id"))
167+
self._cache.setdefault(self.CredentialType.APP_METADATA, {})[key] = {
168+
"client_id": event.get("client_id"),
169+
"environment": environment,
170+
"family_id": response.get("foci"), # None is also valid
171+
}
172+
173+
@staticmethod
174+
def _build_appmetadata_key(environment, client_id):
175+
return "appmetadata-{}-{}".format(environment or "", client_id or "")
176+
165177
@classmethod
166178
def _build_rt_key(
167179
cls,

tests/test_token_cache.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ def testAdd(self):
8888
self.cache._cache["IdToken"].get(
8989
'uid.utid-login.example.com-idtoken-my_client_id-contoso-')
9090
)
91+
self.assertEqual(
92+
{
93+
"client_id": "my_client_id",
94+
'environment': 'login.example.com',
95+
"family_id": None,
96+
},
97+
self.cache._cache.get("AppMetadata", {}).get(
98+
"appmetadata-login.example.com-my_client_id")
99+
)
91100

92101

93102
class SerializableTokenCacheTestCase(TokenCacheTestCase):

0 commit comments

Comments
 (0)