Add custom attributes in Keycloak 21

1,343 views
Skip to first unread message

P Terziev

unread,
Jun 21, 2023, 6:13:27 AM6/21/23
to Keycloak User
I want to add custom value to a customer profile. I found this for older versions of Keycloak: https://www.mastertheboss.com/keycloak/managing-keycloak-user-metadata-and-custom-attributes/

I added:
test_pram1.png

But I get:

    {
        "id""f91296b2-b551-4f77-ba96-53c02e8ccc3d",
        "createdTimestamp"1687173180400,
        "username""test_03c49e0e-d712-48d5-b828-ff23c3f68e7d",
        "enabled"true,
        "totp"false,
        "emailVerified"true,
        "firstName""first 0e413132-17e0-44b2-adc6-4801c7253313",
        "lastName""last 2f0b4767-dbed-4cb6-85fd-72b38fa54929",
        "email""test_4b394779-774d-4965-bd0a-62470391..",
        "attributes": {
            "test_additional_param": [
                "String"
            ]
        },
        "disableableCredentialTypes": [],
        "requiredActions": [],
        "notBefore"0,
        "access": {
            "manageGroupMembership"true,
            "view"true,
            "mapRoles"true,
            "impersonate"true,
            "manage"true
        }
    },

Is there some way to place test_additional_param at the same level as firstName?

Niko Köbler

unread,
Jun 22, 2023, 9:18:39 AM6/22/23
to Keycloak User
That's not possible, as this would required to refactor the use Java classes which are the actual model classes. Firstname, lastname, email and username are "special" attributes, located at the top level, all other attributes are located under the "attributes" node.

Sada Shiv Dash

unread,
Jun 22, 2023, 11:35:35 AM6/22/23
to Niko Köbler, Keycloak User
Just write a wrapper . In keycloak attributes in user model is separate objects.

Regards
Sada Shiv Dash

On 22-Jun-2023, at 6:48 PM, Niko Köbler <niko.k...@gmail.com> wrote:

That's not possible, as this would required to refactor the use Java classes which are the actual model classes. Firstname, lastname, email and username are "special" attributes, located at the top level, all other attributes are located under the "attributes" node.
--
You received this message because you are subscribed to the Google Groups "Keycloak User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keycloak-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/keycloak-user/61c63849-73bb-4d46-96cb-752b96269faen%40googlegroups.com.

Niko Köbler

unread,
Jun 22, 2023, 12:36:41 PM6/22/23
to Keycloak User
Sada Shiv Dash schrieb am Donnerstag, 22. Juni 2023 um 17:35:35 UTC+2:
Just write a wrapper . In keycloak attributes in user model is separate objects.

P Terziev is referring to the internal Keycloak-model of the user (e.g. used in the admin api), not what is put into the token(s). For the Keycloak-model, there is no mapper.

Reply all
Reply to author
Forward
0 new messages