Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Cache will record AppMetadata from now on
  • Loading branch information
rayluo committed Mar 28, 2019
commit f5d30d0e8701029ccec5a927b9981b72a55b0b95
12 changes: 12 additions & 0 deletions msal/token_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class CredentialType:
REFRESH_TOKEN = "RefreshToken"
ACCOUNT = "Account" # Not exactly a credential type, but we put it here
ID_TOKEN = "IdToken"
APP_METADATA = "AppMetadata"

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

key = self._build_appmetadata_key(environment, event.get("client_id"))
self._cache.setdefault(self.CredentialType.APP_METADATA, {})[key] = {
"client_id": event.get("client_id"),
"environment": environment,
"family_id": response.get("foci"), # None is also valid
}

@staticmethod
def _build_appmetadata_key(environment, client_id):
return "appmetadata-{}-{}".format(environment or "", client_id or "")

@classmethod
def _build_rt_key(
cls,
Expand Down
9 changes: 9 additions & 0 deletions tests/test_token_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ def testAdd(self):
self.cache._cache["IdToken"].get(
'uid.utid-login.example.com-idtoken-my_client_id-contoso-')
)
self.assertEqual(
{
"client_id": "my_client_id",
'environment': 'login.example.com',
"family_id": None,
},
self.cache._cache.get("AppMetadata", {}).get(
"appmetadata-login.example.com-my_client_id")
)


class SerializableTokenCacheTestCase(TokenCacheTestCase):
Expand Down