Custom User Attributes If you have custom user data you want to store and manage in the admin console, registration page, and user account service, you can easily add support for it by extending and modifying various Keycloak themes.
In admin console To be able to enter custom attributes in the admin console, take the following steps Create a new theme within the themes/mytheme/admin directory in your distribution. Where mytheme is whatever you want to name your theme. Create a theme.properties file in this directory that extends the main admin console theme. Copy the file themes/base/admin/resources/partials/user-attributes.html into the a mirror directory in your theme: themes/mytheme/admin/resources/partials/user-attributes.html. What you are doing here is overriding the user attribute entry page in the admin console and putting in what attributes you want. This file already contains an example of entering address data. You can remove this if you want and replace it with something else. Also, if you want to edit this file directly instead of creating a new theme, you can. In the user-attributes.html file add your custom user attribute entry form item. For example
]]>
The ng-model names the user attribute you will store in the database and must have the form of user.attributes.ATTR_NAME.
Change the theme for the admin console. Save it, then refresh your browser, and you should now see these fields in the User detail page for any user.
In registration page To be able to enter custom attributes in the registration page, take the following steps Create a new theme within the themes/mytheme/login directory in your distribution. Where mytheme is whatever you want to name your theme. Create a theme.properties file in this directory that extends the main admin console theme. Copy the file themes/base/login/register.ftl into the a mirror directory in your theme: themes/mytheme/login/register.ftl. What you are doing here is overriding the registration page and adding what attributes you want. This file already contains an example of entering address data. You can remove this if you want and replace it with something else. Also, if you want to edit this file directly instead of creating a new theme, you can. In the register.ftl file add your custom user attribute entry form item. For example
]]>
Make sure the input field id ane name match the user attribute you want to store in the database. This must have the form of user.attributes.ATTR_NAME. You might also want to replace the label text with a message property. This will help later if you want to internationalize your pages.
Change the theme for the login to your new theme. Save it, then refresh your browser, and you should now see these fields in the registration.
In user account profile page To be able to manage custom attributes in the user account profile page, take the following steps Create a new theme within the themes/mytheme/account directory in your distribution. Where mytheme is whatever you want to name your theme. Create a theme.properties file in this directory that extends the main admin console theme. Copy the file themes/base/account/account.ftl into the a mirror directory in your theme: themes/mytheme/account/account.ftl. What you are doing here is overriding the profile page and adding what attributes you want to manage. This file already contains an example of entering address data. You can remove this if you want and replace it with something else. Also, if you want to edit this file directly instead of creating a new theme, you can. In the account.ftl file add your custom user attribute entry form item. For example
]]>
Make sure the input field id ane name match the user attribute you want to store in the database. This must have the form of user.attributes.ATTR_NAME. You might also want to replace the label text with a message property. This will help later if you want to internationalize your pages.
Change the theme for the account to your new theme. Save it, then refresh your browser, and you should now see these fields in the account profile page.