goauthentik / authentik

The authentication glue you need.
https://goauthentik.io
Other
13.05k stars 868 forks source link

Add Application icon via API #11097

Open 3isenHeiM opened 1 month ago

3isenHeiM commented 1 month ago

Describe the bug I've tried to add an icon for an application, with a SVG file. I've used this call as stated in the doc, but the file is not correctly rendered.

2024-08-28_14-23

To Reproduce Here is the snippet I'm using:

def add_app_icon(hostname, token, slug, filename):

    if not os.path.isfile(filename):
        print("File '%s' not found. Exiting" %filename)
        exit(1)  

    url = "https://%s/api/v3/core/applications/%s/set_icon/" % (hostname, slug)

    payload = {}
    files={
        'file': ('file',open(filename,'rb'),'image/svg+xml'),
    }

    headers = {
      'Authorization': 'Bearer %s' % token
    }

    try:
        response = requests.request("POST", url, headers=headers, data=payload, files=files, verify=False)

        if not response.ok :
            response.raise_for_status()

        return response.json()

    except Exception as e:
        print(repr(e))
    return None

When firing this request I get an {} back as response content, and a HTTP 200. However the icon is not correctly rendered.

The HTTP POST call to set_icon/ is used upload the SVG but then I do not know how to get the path of the image file to update the application (using a PUT request?).

I've analyzed the API calls when performing this actions in a browser and it's the same behavior.

Expected behavior The SVG file being rendered correctly, or the docs to be updated accordingly.

Version and Deployment (please complete the following information):

3isenHeiM commented 1 month ago

Might be linked to #11029.