From b0c950e99469a99f96a33188631d5fdb139a8d1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Voron?= Date: Thu, 27 Apr 2023 08:47:25 +0200 Subject: [PATCH] Add private methods to set cookies on CookieTransport --- fastapi_users/authentication/transport/cookie.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fastapi_users/authentication/transport/cookie.py b/fastapi_users/authentication/transport/cookie.py index e10527d4..68c6dd90 100644 --- a/fastapi_users/authentication/transport/cookie.py +++ b/fastapi_users/authentication/transport/cookie.py @@ -37,6 +37,13 @@ class CookieTransport(Transport): async def get_login_response(self, token: str) -> Response: response = Response(status_code=status.HTTP_204_NO_CONTENT) + return self._set_login_cookie(response, token) + + async def get_logout_response(self) -> Response: + response = Response(status_code=status.HTTP_204_NO_CONTENT) + return self._set_logout_cookie(response) + + def _set_login_cookie(self, response: Response, token: str) -> Response: response.set_cookie( self.cookie_name, token, @@ -49,8 +56,7 @@ class CookieTransport(Transport): ) return response - async def get_logout_response(self) -> Response: - response = Response(status_code=status.HTTP_204_NO_CONTENT) + def _set_logout_cookie(self, response: Response) -> Response: response.set_cookie( self.cookie_name, "",