我想知道如何在Keycloak中添加自定义属性,以便用户可以在注册时填写额外的字段,而不是使用默认字段,此外,我可能还有一些额外的字段,我需要稍后从后端服务中填写
ki0zmccv1#
是的,你可以像这样在UserRepresentation对象中添加属性:
@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); }
1条答案
按热度按时间ki0zmccv1#
是的,你可以像这样在UserRepresentation对象中添加属性: