@@ -259,7 +259,7 @@ def get_csrf_token(encoded_token):
259
259
return token ["csrf" ]
260
260
261
261
262
- def set_access_cookies (response , encoded_access_token , max_age = None ):
262
+ def set_access_cookies (response , encoded_access_token , max_age = None , domain = None ):
263
263
"""
264
264
Modifiy a Flask Response to set a cookie containing the access JWT.
265
265
Also sets the corresponding CSRF cookies if ``JWT_CSRF_IN_COOKIES`` is ``True``
@@ -276,14 +276,20 @@ def set_access_cookies(response, encoded_access_token, max_age=None):
276
276
``JWT_SESSION_COOKIE`` option (see :ref:`Configuration Options`). Otherwise,
277
277
it will use this as the cookies ``max-age`` and the JWT_SESSION_COOKIE option
278
278
will be ignored. Values should be the number of seconds (as an integer).
279
+
280
+ :param domain:
281
+ The domain of the cookie. If this is None, it will use the
282
+ ``JWT_COOKIE_DOMAIN`` option (see :ref:`Configuration Options`). Otherwise,
283
+ it will use this as the cookies ``domain`` and the JWT_COOKIE_DOMAIN option
284
+ will be ignored.
279
285
"""
280
286
response .set_cookie (
281
287
config .access_cookie_name ,
282
288
value = encoded_access_token ,
283
289
max_age = max_age or config .cookie_max_age ,
284
290
secure = config .cookie_secure ,
285
291
httponly = True ,
286
- domain = config .cookie_domain ,
292
+ domain = domain or config .cookie_domain ,
287
293
path = config .access_cookie_path ,
288
294
samesite = config .cookie_samesite ,
289
295
)
@@ -295,13 +301,13 @@ def set_access_cookies(response, encoded_access_token, max_age=None):
295
301
max_age = max_age or config .cookie_max_age ,
296
302
secure = config .cookie_secure ,
297
303
httponly = False ,
298
- domain = config .cookie_domain ,
304
+ domain = domain or config .cookie_domain ,
299
305
path = config .access_csrf_cookie_path ,
300
306
samesite = config .cookie_samesite ,
301
307
)
302
308
303
309
304
- def set_refresh_cookies (response , encoded_refresh_token , max_age = None ):
310
+ def set_refresh_cookies (response , encoded_refresh_token , max_age = None , domain = None ):
305
311
"""
306
312
Modifiy a Flask Response to set a cookie containing the refresh JWT.
307
313
Also sets the corresponding CSRF cookies if ``JWT_CSRF_IN_COOKIES`` is ``True``
@@ -318,14 +324,20 @@ def set_refresh_cookies(response, encoded_refresh_token, max_age=None):
318
324
``JWT_SESSION_COOKIE`` option (see :ref:`Configuration Options`). Otherwise,
319
325
it will use this as the cookies ``max-age`` and the JWT_SESSION_COOKIE option
320
326
will be ignored. Values should be the number of seconds (as an integer).
327
+
328
+ :param domain:
329
+ The domain of the cookie. If this is None, it will use the
330
+ ``JWT_COOKIE_DOMAIN`` option (see :ref:`Configuration Options`). Otherwise,
331
+ it will use this as the cookies ``domain`` and the JWT_COOKIE_DOMAIN option
332
+ will be ignored.
321
333
"""
322
334
response .set_cookie (
323
335
config .refresh_cookie_name ,
324
336
value = encoded_refresh_token ,
325
337
max_age = max_age or config .cookie_max_age ,
326
338
secure = config .cookie_secure ,
327
339
httponly = True ,
328
- domain = config .cookie_domain ,
340
+ domain = domain or config .cookie_domain ,
329
341
path = config .refresh_cookie_path ,
330
342
samesite = config .cookie_samesite ,
331
343
)
@@ -337,39 +349,45 @@ def set_refresh_cookies(response, encoded_refresh_token, max_age=None):
337
349
max_age = max_age or config .cookie_max_age ,
338
350
secure = config .cookie_secure ,
339
351
httponly = False ,
340
- domain = config .cookie_domain ,
352
+ domain = domain or config .cookie_domain ,
341
353
path = config .refresh_csrf_cookie_path ,
342
354
samesite = config .cookie_samesite ,
343
355
)
344
356
345
357
346
- def unset_jwt_cookies (response ):
358
+ def unset_jwt_cookies (response , domain = None ):
347
359
"""
348
360
Modifiy a Flask Response to delete the cookies containing access or refresh
349
361
JWTs. Also deletes the corresponding CSRF cookies if applicable.
350
362
351
363
:param response:
352
364
A Flask Response object
353
365
"""
354
- unset_access_cookies (response )
355
- unset_refresh_cookies (response )
366
+ unset_access_cookies (response , domain )
367
+ unset_refresh_cookies (response , domain )
356
368
357
369
358
- def unset_access_cookies (response ):
370
+ def unset_access_cookies (response , domain = None ):
359
371
"""
360
372
Modifiy a Flask Response to delete the cookie containing a refresh JWT.
361
373
Also deletes the corresponding CSRF cookie if applicable.
362
374
363
375
:param response:
364
376
A Flask Response object
377
+
378
+ :param domain:
379
+ The domain of the cookie. If this is None, it will use the
380
+ ``JWT_COOKIE_DOMAIN`` option (see :ref:`Configuration Options`). Otherwise,
381
+ it will use this as the cookies ``domain`` and the JWT_COOKIE_DOMAIN option
382
+ will be ignored.
365
383
"""
366
384
response .set_cookie (
367
385
config .access_cookie_name ,
368
386
value = "" ,
369
387
expires = 0 ,
370
388
secure = config .cookie_secure ,
371
389
httponly = True ,
372
- domain = config .cookie_domain ,
390
+ domain = domain or config .cookie_domain ,
373
391
path = config .access_cookie_path ,
374
392
samesite = config .cookie_samesite ,
375
393
)
@@ -381,27 +399,33 @@ def unset_access_cookies(response):
381
399
expires = 0 ,
382
400
secure = config .cookie_secure ,
383
401
httponly = False ,
384
- domain = config .cookie_domain ,
402
+ domain = domain or config .cookie_domain ,
385
403
path = config .access_csrf_cookie_path ,
386
404
samesite = config .cookie_samesite ,
387
405
)
388
406
389
407
390
- def unset_refresh_cookies (response ):
408
+ def unset_refresh_cookies (response , domain = None ):
391
409
"""
392
410
Modifiy a Flask Response to delete the cookie containing an access JWT.
393
411
Also deletes the corresponding CSRF cookie if applicable.
394
412
395
413
:param response:
396
414
A Flask Response object
415
+
416
+ :param domain:
417
+ The domain of the cookie. If this is None, it will use the
418
+ ``JWT_COOKIE_DOMAIN`` option (see :ref:`Configuration Options`). Otherwise,
419
+ it will use this as the cookies ``domain`` and the JWT_COOKIE_DOMAIN option
420
+ will be ignored.
397
421
"""
398
422
response .set_cookie (
399
423
config .refresh_cookie_name ,
400
424
value = "" ,
401
425
expires = 0 ,
402
426
secure = config .cookie_secure ,
403
427
httponly = True ,
404
- domain = config .cookie_domain ,
428
+ domain = domain or config .cookie_domain ,
405
429
path = config .refresh_cookie_path ,
406
430
samesite = config .cookie_samesite ,
407
431
)
@@ -413,7 +437,7 @@ def unset_refresh_cookies(response):
413
437
expires = 0 ,
414
438
secure = config .cookie_secure ,
415
439
httponly = False ,
416
- domain = config .cookie_domain ,
440
+ domain = domain or config .cookie_domain ,
417
441
path = config .refresh_csrf_cookie_path ,
418
442
samesite = config .cookie_samesite ,
419
443
)
0 commit comments