auth0 / auth0-python

Auth0 SDK for Python
https://auth0-python.readthedocs.io
MIT License
513 stars 165 forks source link

Both `remove_permissions` and `add_permissions` from `auth0.management.users.Users` have wrong `permission` representation #622

Open ayharano opened 4 months ago

ayharano commented 4 months ago

Checklist

Description

Checking the API docs from

we can verify that a permission is represented by a dict with two values:

    {
      "resource_server_identifier": "string",
      "permission_name": "string"
    }

while the auth0-python implementation expects str (referring to 4.7.1 code snippet: [link]

(method reference: auth0.management.users.Users.remove_permissions and auth0.management.users.Users.add_permissions)

Reproduction

Using a CPython 3.12.3 venv with auth0-python 4.7.1

>>> from auth0.management.auth0 import Auth0
>>> auth0_ = Auth0(
...     domain="MY_DOMAIN",
...     token="MY_TOKEN",
... )
>>> auth0_.users.add_permissions(id="USER_ID", permissions=["EXISTING_PERMISSION_NAME"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/project/.venv/lib/python3.12/site-packages/auth0/management/users.py", line 309, in add_permissions
    return self.client.post(url, data=body)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/project/.venv/lib/python3.12/site-packages/auth0/rest.py", line 207, in post
    return self._request("POST", url, json=data, headers=request_headers)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/project/.venv/lib/python3.12/site-packages/auth0/rest.py", line 187, in _request
    return self._process_response(response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/project/.venv/lib/python3.12/site-packages/auth0/rest.py", line 258, in _process_response
    return self._parse(response).content()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/project/.venv/lib/python3.12/site-packages/auth0/rest.py", line 294, in content
    raise Auth0Error(
auth0.exceptions.Auth0Error: 400: Payload validation error: 'Expected type object but found type string' on property permissions[0].
>>>

Additional context

No response

auth0-python version

4.7.1

Python version

3.12.3