Custom Attributes not displayed and saved properly in "Settings"->"User details"
Describe your question/ I'm currently playing around with custom user attributes and they look great! I can type and save something in the custom attributes under "Settings"->"User details" and it's saved to the user attributes and clearly visible in the event log. However, it is not shown there after being saved - the fields are just at their defaults afterwards.
Screenshots
- Fill details and save
- User details are empty directly after clicking on save
- Event log shows that data was saved
- Data is visible in update user page
Logs I can provide this if requested.
Version and Deployment (please complete the following information):
- authentik version: 2024.6.0
- Deployment: docker-compose
Can anybody help me?
Nobody? If not, I consider this a bug and change labels
There is no implied bi-directional binding between prompt fields and user attributes, meaning you need to ensure the data gets loaded too. I recommend looking at the prompt fields from the default user settings flow for username/name/etc
Thanks, that helped! I totally missed that field. Ticking the "Interpret initial value as expression" box and setting initial value e.g. for test_description like that fixed it (the default-user-settings-field-locale even stacks this):
try:
return user.attributes.get("test_description", "default value")
except:
return ''
That worked well for radio buttons and text. I didn't get it working for a checkbox or a file. And as those values are not loaded in the settings page, updating the settings without reuploading the file or setting the correct checkbox value causes the file to be deleted from the user attributes and the checkbox value to be set to the default.
I even discovered a bug (report will follow): Entering incorrect python code prevents makes it impossible to edit the prompt - it'll just load forever. (should be fixed by now in https://github.com/goauthentik/authentik/issues/10592)
Any ideas how to fix this?
Returning a value for a checkbox should be possible, the frontend checks if the initial value is a non-empty string. For file uploads, it's not possible to "load" a value into such an element, so additional logic has to be added in the prompt to not overwrite the attribute with an empty value
Sorry for the probably stupid question, but neither a search on google, reddit nor github helped me find out how you added the custom attributes to the user details form? @eickeh
In my system settings there is no such option :/
I think I just took some time to search the UI to find it, not sure if there are docs specifically for this. As far as I understood this, there is not much difference between the forms shown in the user settings and the login forms. You can use both at both places.
To get your field in, go to "Flows and Stages"->"Stages" and edit the "default-user-settings" Stage and add your new field.
Answered above: prompt fields need an initial value expression such as return user.attributes.get("my_field", "") to show the saved value. The checkbox part is tracked in #27014.