16
16
get_algorithm , get_blacklist_enabled , get_blacklist_checks , get_jwt_header_type , \
17
17
get_access_cookie_name , get_cookie_secure , get_access_cookie_path , \
18
18
get_cookie_csrf_protect , get_access_csrf_cookie_name , \
19
- get_refresh_cookie_name , get_refresh_cookie_path , \
19
+ get_refresh_cookie_name , get_refresh_cookie_path , get_session_cookie , \
20
20
get_refresh_csrf_cookie_name , get_token_location , \
21
21
get_csrf_header_name , get_jwt_header_name , get_csrf_request_methods
22
22
from flask_jwt_extended .exceptions import JWTEncodeError , JWTDecodeError , \
@@ -49,6 +49,14 @@ def get_raw_jwt():
49
49
return getattr (ctx_stack .top , 'jwt' , {})
50
50
51
51
52
+ def _get_cookie_max_age ():
53
+ """
54
+ Checks config value for using session or persistent cookies and returns the
55
+ appropriate value for flask set_cookies.
56
+ """
57
+ return None if get_session_cookie () else 2147483647 # 2^31
58
+
59
+
52
60
def _create_csrf_token ():
53
61
return str (uuid .uuid4 ())
54
62
@@ -395,6 +403,7 @@ def set_access_cookies(response, encoded_access_token):
395
403
# Set the access JWT in the cookie
396
404
response .set_cookie (get_access_cookie_name (),
397
405
value = encoded_access_token ,
406
+ max_age = _get_cookie_max_age (),
398
407
secure = get_cookie_secure (),
399
408
httponly = True ,
400
409
path = get_access_cookie_path ())
@@ -403,6 +412,7 @@ def set_access_cookies(response, encoded_access_token):
403
412
if get_cookie_csrf_protect ():
404
413
response .set_cookie (get_access_csrf_cookie_name (),
405
414
value = _get_csrf_token (encoded_access_token ),
415
+ max_age = _get_cookie_max_age (),
406
416
secure = get_cookie_secure (),
407
417
httponly = False ,
408
418
path = '/' )
@@ -420,6 +430,7 @@ def set_refresh_cookies(response, encoded_refresh_token):
420
430
# Set the refresh JWT in the cookie
421
431
response .set_cookie (get_refresh_cookie_name (),
422
432
value = encoded_refresh_token ,
433
+ max_age = _get_cookie_max_age (),
423
434
secure = get_cookie_secure (),
424
435
httponly = True ,
425
436
path = get_refresh_cookie_path ())
@@ -428,6 +439,7 @@ def set_refresh_cookies(response, encoded_refresh_token):
428
439
if get_cookie_csrf_protect ():
429
440
response .set_cookie (get_refresh_csrf_cookie_name (),
430
441
value = _get_csrf_token (encoded_refresh_token ),
442
+ max_age = _get_cookie_max_age (),
431
443
secure = get_cookie_secure (),
432
444
httponly = False ,
433
445
path = '/' )
0 commit comments