Reputation: 1086
I'm working with Keycloak 26 and want to define custom user attributes (e.g. user_type ) at the realm level so they appear in the user profile.
Here's what I've tried in my Java (Spring Boot) service, which uses the Keycloak Admin Client:
public void defineUserAttributes(String realmName) {
RealmResource realmResource = keycloak.realm(realmName);
RealmRepresentation realmRep = realmResource.toRepresentation();
realmRep.getAttributes().put("userProfileEnabled", "true");
String userProfileConfigJson = ""
" {
"attributes": [{
"name": "user_type",
"required": false
}, ]
}
""
";
realmRep.getAttributes().put("userProfileConfiguration", userProfileConfigJson);
realmResource.update(realmRep);
}
But it seems this is not working. Can someone help me with this? When I do it manually, I can update them from here in the Realm settings.
Upvotes: 0
Views: 269