mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-08-15 19:30:47 +08:00
Cookie transport must return empty json and not null
in response.data
on login (#1037)
* Fix: LoginResponse is set to application/json, and should return response with status code 204 when body is empty. The database backend login response is a cookie header with empty body. This causes issues when integrating the openapi schema into openapi-generator. Because the code generator expects the response to be a JSON when the status code isn't 204. * Fix: Bump fastapi version to appropriate version for status code 204 handling. * Build a full response for CookieTransport login_response Co-authored-by: Can H. Tartanoglu <2947298-caniko@users.noreply.gitlab.com> Co-authored-by: François Voron <fvoron@gmail.com>
This commit is contained in:

committed by
GitHub

parent
580dfced4c
commit
77d0077503
@ -30,6 +30,7 @@ class CookieTransport(Transport):
|
||||
self.scheme = APIKeyCookie(name=self.cookie_name, auto_error=False)
|
||||
|
||||
async def get_login_response(self, token: str, response: Response) -> Any:
|
||||
response = Response(status_code=status.HTTP_204_NO_CONTENT)
|
||||
response.set_cookie(
|
||||
self.cookie_name,
|
||||
token,
|
||||
@ -40,10 +41,7 @@ class CookieTransport(Transport):
|
||||
httponly=self.cookie_httponly,
|
||||
samesite=self.cookie_samesite,
|
||||
)
|
||||
|
||||
# We shouldn't return directly the response
|
||||
# so that FastAPI can terminate it properly
|
||||
return None
|
||||
return response
|
||||
|
||||
async def get_logout_response(self, response: Response) -> Any:
|
||||
response.set_cookie(
|
||||
@ -59,7 +57,7 @@ class CookieTransport(Transport):
|
||||
|
||||
@staticmethod
|
||||
def get_openapi_login_responses_success() -> OpenAPIResponseType:
|
||||
return {status.HTTP_200_OK: {"model": None}}
|
||||
return {status.HTTP_204_NO_CONTENT: {"model": None}}
|
||||
|
||||
@staticmethod
|
||||
def get_openapi_logout_responses_success() -> OpenAPIResponseType:
|
||||
|
Reference in New Issue
Block a user