diff --git a/msal/token_cache.py b/msal/token_cache.py index e726dc6e..358b064b 100644 --- a/msal/token_cache.py +++ b/msal/token_cache.py @@ -54,7 +54,7 @@ def __init__(self): home_account_id or "", environment or "", self.CredentialType.ACCESS_TOKEN, - client_id, + client_id or "", realm or "", target or "", ]).lower(), @@ -128,8 +128,11 @@ def add(self, event, now=None): with self._lock: if access_token: - now = time.time() if now is None else now - expires_in = response.get("expires_in", 3599) + now = int(time.time() if now is None else now) + expires_in = int( # AADv1-like endpoint returns a string + response.get("expires_in", 3599)) + ext_expires_in = int( # AADv1-like endpoint returns a string + response.get("ext_expires_in", expires_in)) at = { "credential_type": self.CredentialType.ACCESS_TOKEN, "secret": access_token, @@ -138,10 +141,9 @@ def add(self, event, now=None): "client_id": event.get("client_id"), "target": target, "realm": realm, - "cached_at": str(int(now)), # Schema defines it as a string - "expires_on": str(int(now + expires_in)), # Same here - "extended_expires_on": str(int( # Same here - now + response.get("ext_expires_in", expires_in))), + "cached_at": str(now), # Schema defines it as a string + "expires_on": str(now + expires_in), # Same here + "extended_expires_on": str(now + ext_expires_in) # Same here } self.modify(self.CredentialType.ACCESS_TOKEN, at, at)