Logout API not working
Hi, I am using the python client to logout a user. Unfortunately, I am getting the following response from the server.
{
"fieldErrors":{
"global":[
{
"code":"[couldNotConvert]global",
"message":"Invalid"
}
]
}
}
Here is my code:
token = serializer.get_cleaned_data()["refreshToken"]
print(token)
client_response = anonymous_client.logout(True, token)
if not client_response.was_successful():
code = client_response.response.status_code
raise UnKnownError(http_code_number=code)
return Response({"detail": "Successfully logged out."}, status=status.HTTP_200_OK)
Versions Fusionauth-client 1.19.8 FusionAuth 1.19.8
What happens if you try with
client_response = anonymous_client.logout(False, token)
do you still get an error?
Yes, I get the same error. The HTTP status code is always 400.
My guess is that the True is not serializing to the lower case true when converted to a request parameter.
Here is where we build the request parameter: https://github.com/FusionAuth/fusionauth-client-builder/blob/d64a871ba9d8fcedc7922bddced491ec80b5bd02/src/main/client/python.client.ftl#L76
And here is where we manage conversions for Python: https://github.com/FusionAuth/fusionauth-client-builder/blob/d64a871ba9d8fcedc7922bddced491ec80b5bd02/src/main/client/_macros.ftl#L197
So we may have a bug in our builder since we should probably expect True or False.
https://docs.python.org/3/library/stdtypes.html#bltin-boolean-values
As a work around, what if you try passing "true" instead of True and see if that helps.
As a work around, what if you try passing
"true"instead ofTrueand see if that helps.
This fixes the issue. Should I close it?
Please leave it open, so we can fix the issue. As @robotdan says, we should handle True correctly.
https://github.com/FusionAuth/fusionauth-python-client/pull/11 documents the workaround.
Have a fix for this in the code: https://github.com/FusionAuth/fusionauth-client-builder/pull/46
Added test for it here: https://github.com/FusionAuth/fusionauth-python-client/pull/16
This test will fail until there's a new release, but I've checked it manually and https://github.com/FusionAuth/fusionauth-client-builder/pull/46 will cause the test to pass.
The fix is merged and will be included in the next release of the client library.