Hi,
I am implementing some backend logic and I would like to create some permissions on the fly so I can add them to my user roles when specific user events occur.
I found this page on how to update permissions on a specified API, but when I call it , get a strange error:
{
'error': 'Bad Request',
'errorCode': 'invalid_body', '
message': ""Payload validation error: 'Expected type object but found type string'
on property scopes[3]. (also) Payload validation error: 'Expected type object but
found type string' on property scopes[2]. (also) Payload validation error:
'Expected type object but found type string' on property scopes[1].
(also) Payload validation error: 'Expected type object but
found type string' on property scopes[0]."", '
statusCode': 400
}
My backend is in python and this is what I did:
import os
import requests
AUTH0_BASE_URL = os.getenv("MY_ENV_VAR")
def add_permissions_to_api(apiid, permissions):
"""
add a permission to a specified api
@params apiid: string of api id: eg for _my_api <api_id_hex_string>
@param permissions: List[tuple] list of (permission name, permission description)
eg: [("read:test1", "read on resource test1"), ("write:test2", "write permission on resource test2")]
"""
ENDPT = "api/v2/resource-servers"
auth = get_token()
headers = {"Authorization": f"{auth['token_type']} {auth['access_token']}"}
data = {"scopes":[dict(zip(("value","description"),(i[0], i[1]))) for i in permissions]}
url = "/".join([AUTH0_BASE_URL, ENDPT, apiid])
return requests.patch(url, data=data, headers=headers).json()
I checked many times and I have formatted my payload exactly as in the example link above.
Any idea how I can deal with this please?
Thanks