1616 get_algorithm , get_blacklist_enabled , get_blacklist_checks , get_jwt_header_type , \
1717 get_access_cookie_name , get_cookie_secure , get_access_cookie_path , \
1818 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 , \
2020 get_refresh_csrf_cookie_name , get_token_location , \
2121 get_csrf_header_name , get_jwt_header_name , get_csrf_request_methods
2222from flask_jwt_extended .exceptions import JWTEncodeError , JWTDecodeError , \
@@ -49,6 +49,14 @@ def get_raw_jwt():
4949 return getattr (ctx_stack .top , 'jwt' , {})
5050
5151
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+
5260def _create_csrf_token ():
5361 return str (uuid .uuid4 ())
5462
@@ -395,6 +403,7 @@ def set_access_cookies(response, encoded_access_token):
395403 # Set the access JWT in the cookie
396404 response .set_cookie (get_access_cookie_name (),
397405 value = encoded_access_token ,
406+ max_age = _get_cookie_max_age (),
398407 secure = get_cookie_secure (),
399408 httponly = True ,
400409 path = get_access_cookie_path ())
@@ -403,6 +412,7 @@ def set_access_cookies(response, encoded_access_token):
403412 if get_cookie_csrf_protect ():
404413 response .set_cookie (get_access_csrf_cookie_name (),
405414 value = _get_csrf_token (encoded_access_token ),
415+ max_age = _get_cookie_max_age (),
406416 secure = get_cookie_secure (),
407417 httponly = False ,
408418 path = '/' )
@@ -420,6 +430,7 @@ def set_refresh_cookies(response, encoded_refresh_token):
420430 # Set the refresh JWT in the cookie
421431 response .set_cookie (get_refresh_cookie_name (),
422432 value = encoded_refresh_token ,
433+ max_age = _get_cookie_max_age (),
423434 secure = get_cookie_secure (),
424435 httponly = True ,
425436 path = get_refresh_cookie_path ())
@@ -428,6 +439,7 @@ def set_refresh_cookies(response, encoded_refresh_token):
428439 if get_cookie_csrf_protect ():
429440 response .set_cookie (get_refresh_csrf_cookie_name (),
430441 value = _get_csrf_token (encoded_refresh_token ),
442+ max_age = _get_cookie_max_age (),
431443 secure = get_cookie_secure (),
432444 httponly = False ,
433445 path = '/' )
0 commit comments