I wonder how can I add custom attributes in Keycloak so the user can fill additional fields upon registration rather than using the default ones, also I might have some additional fields that I would need to fill later from my backend service
Asked
Active
Viewed 149 times
0
-
You can add custom fields in [here](https://stackoverflow.com/questions/75530965/how-to-add-programmed-custom-field-to-keycloak-user/75532971#75532971) and search by custom value. – Bench Vue Feb 28 '23 at 21:17
1 Answers
1
Yes you can add attributes in UserRepresentation object like this:
@Autowired
private final Keycloak keycloak;
public void createUser(UserDTO userDTO){
UserRepresentation user = new UserRepresentation();
user.setUsername(userDTO.getUsername());
user.setEmail(userDTO.getEmailAddress());
user.setFirstName(userDTO.getFirstName());
user.setLastName(userDTO.getLastName());
RealmResource realmResource = keycloak.realm(REALM);
UsersResource userRessource = realmResource.users();
Map<String, List<String>> attr = new HashMap<>;// create your attr
user.setAttributes(attr);
// Create user
Response result = userRessource.create(user);
}

bizhan-laripour
- 11
- 4