Skip to content

Commit 8a590fc

Browse files
committed
Expire cached jwt after 1h if no expiry is set
1 parent a506e52 commit 8a590fc

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

pomerium_http_adapter/pomerium_http_adapter.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,23 @@ def _extract_expiry(self, jwt):
196196
except Exception as original_exception:
197197
raise Exception('%s: "%s"' % (error_message, original_exception))
198198

199-
if not type(jwt_data_parsed) is dict and not 'exp' in jwt_data_parsed.keys():
199+
if not type(jwt_data_parsed) is dict:
200200
raise Exception(error_message)
201201

202-
try:
203-
expiry = int(jwt_data_parsed['exp'])
202+
if 'exp' in jwt_data_parsed.keys():
203+
try:
204+
expiry = int(jwt_data_parsed['exp'])
204205

205-
except Exception as original_exception:
206-
raise Exception('%s: "%s"' % (error_message, original_exception))
206+
except Exception as original_exception:
207+
raise Exception('%s: "%s"' % (error_message, original_exception))
208+
209+
_log.debug('Extracted expiry time: %i' % expiry)
210+
211+
# Seems that expiry isn't always passed on, set token to expire in 1 hour in those cases
212+
else:
213+
expiry = int(time.time() + 3600)
207214

208-
_log.debug('Extracted expiry time: %i' % expiry)
215+
_log.debug('Expiry not found in JWT, expiry time set to: %i' % expiry)
209216

210217
return expiry
211218

0 commit comments

Comments
 (0)