@@ -259,7 +259,7 @@ def get_csrf_token(encoded_token):
259259    return  token ["csrf" ]
260260
261261
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 ):
263263    """ 
264264    Modifiy a Flask Response to set a cookie containing the access JWT. 
265265    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):
276276        ``JWT_SESSION_COOKIE`` option (see :ref:`Configuration Options`). Otherwise, 
277277        it will use this as the cookies ``max-age`` and the JWT_SESSION_COOKIE option 
278278        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. 
279285    """ 
280286    response .set_cookie (
281287        config .access_cookie_name ,
282288        value = encoded_access_token ,
283289        max_age = max_age  or  config .cookie_max_age ,
284290        secure = config .cookie_secure ,
285291        httponly = True ,
286-         domain = config .cookie_domain ,
292+         domain = domain   or   config .cookie_domain ,
287293        path = config .access_cookie_path ,
288294        samesite = config .cookie_samesite ,
289295    )
@@ -295,13 +301,13 @@ def set_access_cookies(response, encoded_access_token, max_age=None):
295301            max_age = max_age  or  config .cookie_max_age ,
296302            secure = config .cookie_secure ,
297303            httponly = False ,
298-             domain = config .cookie_domain ,
304+             domain = domain   or   config .cookie_domain ,
299305            path = config .access_csrf_cookie_path ,
300306            samesite = config .cookie_samesite ,
301307        )
302308
303309
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 ):
305311    """ 
306312    Modifiy a Flask Response to set a cookie containing the refresh JWT. 
307313    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):
318324        ``JWT_SESSION_COOKIE`` option (see :ref:`Configuration Options`). Otherwise, 
319325        it will use this as the cookies ``max-age`` and the JWT_SESSION_COOKIE option 
320326        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. 
321333    """ 
322334    response .set_cookie (
323335        config .refresh_cookie_name ,
324336        value = encoded_refresh_token ,
325337        max_age = max_age  or  config .cookie_max_age ,
326338        secure = config .cookie_secure ,
327339        httponly = True ,
328-         domain = config .cookie_domain ,
340+         domain = domain   or   config .cookie_domain ,
329341        path = config .refresh_cookie_path ,
330342        samesite = config .cookie_samesite ,
331343    )
@@ -337,39 +349,45 @@ def set_refresh_cookies(response, encoded_refresh_token, max_age=None):
337349            max_age = max_age  or  config .cookie_max_age ,
338350            secure = config .cookie_secure ,
339351            httponly = False ,
340-             domain = config .cookie_domain ,
352+             domain = domain   or   config .cookie_domain ,
341353            path = config .refresh_csrf_cookie_path ,
342354            samesite = config .cookie_samesite ,
343355        )
344356
345357
346- def  unset_jwt_cookies (response ):
358+ def  unset_jwt_cookies (response ,  domain = None ):
347359    """ 
348360    Modifiy a Flask Response to delete the cookies containing access or refresh 
349361    JWTs.  Also deletes the corresponding CSRF cookies if applicable. 
350362
351363    :param response: 
352364        A Flask Response object 
353365    """ 
354-     unset_access_cookies (response )
355-     unset_refresh_cookies (response )
366+     unset_access_cookies (response ,  domain )
367+     unset_refresh_cookies (response ,  domain )
356368
357369
358- def  unset_access_cookies (response ):
370+ def  unset_access_cookies (response ,  domain = None ):
359371    """ 
360372    Modifiy a Flask Response to delete the cookie containing a refresh JWT. 
361373    Also deletes the corresponding CSRF cookie if applicable. 
362374
363375    :param response: 
364376        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. 
365383    """ 
366384    response .set_cookie (
367385        config .access_cookie_name ,
368386        value = "" ,
369387        expires = 0 ,
370388        secure = config .cookie_secure ,
371389        httponly = True ,
372-         domain = config .cookie_domain ,
390+         domain = domain   or   config .cookie_domain ,
373391        path = config .access_cookie_path ,
374392        samesite = config .cookie_samesite ,
375393    )
@@ -381,27 +399,33 @@ def unset_access_cookies(response):
381399            expires = 0 ,
382400            secure = config .cookie_secure ,
383401            httponly = False ,
384-             domain = config .cookie_domain ,
402+             domain = domain   or   config .cookie_domain ,
385403            path = config .access_csrf_cookie_path ,
386404            samesite = config .cookie_samesite ,
387405        )
388406
389407
390- def  unset_refresh_cookies (response ):
408+ def  unset_refresh_cookies (response ,  domain = None ):
391409    """ 
392410    Modifiy a Flask Response to delete the cookie containing an access JWT. 
393411    Also deletes the corresponding CSRF cookie if applicable. 
394412
395413    :param response: 
396414        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. 
397421    """ 
398422    response .set_cookie (
399423        config .refresh_cookie_name ,
400424        value = "" ,
401425        expires = 0 ,
402426        secure = config .cookie_secure ,
403427        httponly = True ,
404-         domain = config .cookie_domain ,
428+         domain = domain   or   config .cookie_domain ,
405429        path = config .refresh_cookie_path ,
406430        samesite = config .cookie_samesite ,
407431    )
@@ -413,7 +437,7 @@ def unset_refresh_cookies(response):
413437            expires = 0 ,
414438            secure = config .cookie_secure ,
415439            httponly = False ,
416-             domain = config .cookie_domain ,
440+             domain = domain   or   config .cookie_domain ,
417441            path = config .refresh_csrf_cookie_path ,
418442            samesite = config .cookie_samesite ,
419443        )
0 commit comments