Skip to content

Commit cff23ee

Browse files
committed
Fallback to expires_on when expires_in is absent
1 parent c339ec3 commit cff23ee

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

msal/token_cache.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,11 @@ def __add(self, event, now=None):
164164
now = int(time.time() if now is None else now)
165165

166166
if access_token:
167+
default_expires_in = ( # https://www.rfc-editor.org/rfc/rfc6749#section-5.1
168+
int(response.get("expires_on")) - now # Some Managed Identity emits this
169+
) if response.get("expires_on") else 600
167170
expires_in = int( # AADv1-like endpoint returns a string
168-
response.get("expires_in", 3599))
171+
response.get("expires_in", default_expires_in))
169172
ext_expires_in = int( # AADv1-like endpoint returns a string
170173
response.get("ext_expires_in", expires_in))
171174
at = {

0 commit comments

Comments
 (0)