fusionauth-python-client icon indicating copy to clipboard operation
fusionauth-python-client copied to clipboard

Logout API not working

Open tanwirahmad opened this issue 5 years ago • 9 comments

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

tanwirahmad avatar Oct 15 '20 17:10 tanwirahmad

What happens if you try with

client_response = anonymous_client.logout(False, token)

do you still get an error?

mooreds avatar Oct 16 '20 20:10 mooreds

Yes, I get the same error. The HTTP status code is always 400.

tanwirahmad avatar Oct 17 '20 13:10 tanwirahmad

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.

robotdan avatar Oct 17 '20 19:10 robotdan

As a work around, what if you try passing "true" instead of True and see if that helps.

This fixes the issue. Should I close it?

tanwirahmad avatar Oct 19 '20 10:10 tanwirahmad

Please leave it open, so we can fix the issue. As @robotdan says, we should handle True correctly.

mooreds avatar Oct 19 '20 15:10 mooreds

https://github.com/FusionAuth/fusionauth-python-client/pull/11 documents the workaround.

mooreds avatar Dec 15 '20 17:12 mooreds

Have a fix for this in the code: https://github.com/FusionAuth/fusionauth-client-builder/pull/46

mooreds avatar May 02 '22 23:05 mooreds

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.

mooreds avatar May 04 '22 21:05 mooreds

The fix is merged and will be included in the next release of the client library.

mooreds avatar May 05 '22 18:05 mooreds