Add a custom user profile attribute via realm.json

Hey all,

Is there a way to add a custom user profile attribute (in my case picture URL) via realm.json in Keycloak without having to redefine all the default attributes (username, email, first name, etc.)?

I want to avoid to define all the default attributes again because they can change (also their constraints) at any time during releases and to detect such changes is quiet time consuming (sure it could be somehow automated but would like to avoid it).

I’m not sure if this is relevant or not as I’m not entirely sure what you’re trying to do. But in one of my applications I add a custom realm attribute via the keycloak admin api. Here’s the code in java. I would assume it is also possible to add a custom user attribute via the admin api.

RealmRepresentation realmRepresentation = keycloak.realm(realm).toRepresentation();
		
Map<String, String> existingRealmAttributes = realmRepresentation.getAttributes();
		
existingRealmAttributes.put("someAttribute", "someValue");
		
keycloak.realm(realm).update(realmRepresentation);

@SailReal I don’t think there is something like you desire. If you want to define a custom user profile attribute, you also will have to specify the default ones. The default ones are only created, if there is nothing specified at realm creation time.

@jeffvictor The OP didn’t mean the standard attributes at a user, but the declared User Profile attributes, which are here since v24.x.

Thanks for the confirmation.

Is there a way to track the default user profile attribute of keycloak if a new release is published without deploying a new instance and exporting the realm?

I want to make sure that I am as close as possible to the defaults also in the future.

I don’t know, but defaults are just few most generic ones:
username, email, firstName and lastName
I think there is nothing specific to track here I guess. But you can always read release notes before update it should be mentioned something about adding new defaults?