r/Authentik • • Sep 24 '26

Weird behavior with proxy/forward_auth provider after enabling profile photo uploads

I am relatively new to Authentik and am loving it so far. I use it for SSO for my modest homelab, which I use to host a small number of private services for my immediate family. I managed to set up a number of Applications and Providers for my local services, and everything was working well, when I discovered the option for enabling custom avatar uploads. I created a custom.avatar.upload prompt and integrated it into the settings flow and uploaded a profile avatar for my account. I quickly discovered that the default OpenID 'profile' scope includes the actual uploaded avatar in its payload, which can be too big for many applications/integrations. So I created a custom profile scope that excludes the avatar in its payload and started switching to that custom scope for the applications/providers that broke with the profile picture included.

I was unable to change the scopes of one proxy/forward_auth provider. I use Hubitat for home automation devices, and had created a proxy/forward_auth provider that allows me to keep my Hubitat C8 Pro's interface behind Authentik's authenication. But that provider broke when it received my large profile picture, so I tried to switch over to my custom profile scope. Strangely, it won't let me. I've tried to remove the default OpenID 'profile' scope several times (saving each time), and each time it immediately returns to the provider's scopes list. I am simply unable to remove the default OpenID 'profile' scope from the provider. I even tried removing the provider from association with my Outpost and then removing the scope, but nothing worked. I intend to delete the whole Application/Provider pair and recreate it from scratch, but find it odd that Authentik will not permit me to delete the scope. Is this normal or expected behavior for proxy/forward_auth providers?

5 Upvotes

1 comment sorted by

1

u/ColoradoDilettante Sep 25 '26

For what it's worth, as far as I can tell the default OpenID 'profile' scope is automatically included for all proxy/forward_auth providers. I removed the initial provider from my outpost, deleted the provider and application, and tried to recreate the application and provider using only my custom profile-without-avatar scope and not the default OpenID 'profile' scope. But when I tried to access my application , I got the same error as before. I checked the provider, and the default OpenID 'profile' scope was automatically added to the provider.

I was able to make my installation work again by creating the Expression Policy below, bind mounting a host directory to /media/public/user-avatars/ and then altering the default OpenID 'profile' property/scope mapping to output a URL instead of the serialized image file. Here's the Expression Policy I'm using:

# Inspired by https://github.com/goauthentik/authentik/discussions/6824
# Simplified Expression Policy with help from Google Gemini AI
import os
from base64 import b64decode

# 1. Define your external domain and local media path
AK_DOMAIN = "authentik.example.com"  # Change to your actual Authentik domain
FILE_DIR = "/media/public/user-avatars/"
os.makedirs(FILE_DIR, exist_ok=True)

prompt_data = request.context.get("prompt_data", {})
uploaded_file = prompt_data.get("avatar") # matches your Prompt field key

if uploaded_file and "base64," in uploaded_file:
    # 2. Extract header and base64 payload
    header, base64_data = uploaded_file.split("base64,")
    file_bytes = b64decode(base64_data)
    
    # Determine extension
    ext = "png"
    if "image/jpeg" in header: ext = "jpg"
    elif "image/webp" in header: ext = "webp"
    
    # 3. Save file using a stable name template (e.g., username)
    filename = f"{request.user.username}.{ext}"
    full_path = os.path.join(FILE_DIR, filename)
    
    with open(full_path, "wb") as f:
        f.write(file_bytes)
        
    # 4. Save a stable, clean public URL string to the user's attributes
    request.user.attributes["avatar_url"] = f"https://{AK_DOMAIN}{FILE_DIR}{filename}"
    request.user.save()

return True

I modified the authentik default OAuth Mapping: OpenID 'profile' to define avatar_link = request.user.attributes.get("avatar_url", "") and then to return "picture": avatar_link.

Good luck, everyone.