FusionAuth / fusionauth-python-client

FusionAuth Python Client
https://fusionauth.io
Apache License 2.0
24 stars 12 forks source link

Logout API not working #10

Open tanwirahmad opened 3 years ago

tanwirahmad commented 3 years ago

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

mooreds commented 3 years ago

What happens if you try with

client_response = anonymous_client.logout(False, token)

do you still get an error?

tanwirahmad commented 3 years ago

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

robotdan commented 3 years ago

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.

tanwirahmad commented 3 years ago

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?

mooreds commented 3 years ago

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

mooreds commented 3 years ago

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

mooreds commented 2 years ago

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

mooreds commented 2 years ago

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 commented 2 years ago

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